Skip to content

Commit

Permalink
Rename wsgi -> http
Browse files Browse the repository at this point in the history
  • Loading branch information
balloob committed Oct 23, 2016
1 parent 51c4c40 commit db9b7e8
Show file tree
Hide file tree
Showing 20 changed files with 64 additions and 62 deletions.
4 changes: 2 additions & 2 deletions homeassistant/components/alexa.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ def setup(hass, config):
intents = config[DOMAIN].get(CONF_INTENTS, {})
flash_briefings = config[DOMAIN].get(CONF_FLASH_BRIEFINGS, {})

hass.wsgi.register_view(AlexaIntentsView(hass, intents))
hass.wsgi.register_view(AlexaFlashBriefingView(hass, flash_briefings))
hass.http.register_view(AlexaIntentsView(hass, intents))
hass.http.register_view(AlexaFlashBriefingView(hass, flash_briefings))

return True

Expand Down
28 changes: 14 additions & 14 deletions homeassistant/components/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,20 @@

def setup(hass, config):
"""Register the API with the HTTP interface."""
hass.wsgi.register_view(APIStatusView)
hass.wsgi.register_view(APIEventStream)
hass.wsgi.register_view(APIConfigView)
hass.wsgi.register_view(APIDiscoveryView)
hass.wsgi.register_view(APIStatesView)
hass.wsgi.register_view(APIEntityStateView)
hass.wsgi.register_view(APIEventListenersView)
hass.wsgi.register_view(APIEventView)
hass.wsgi.register_view(APIServicesView)
hass.wsgi.register_view(APIDomainServicesView)
hass.wsgi.register_view(APIEventForwardingView)
hass.wsgi.register_view(APIComponentsView)
hass.wsgi.register_view(APIErrorLogView)
hass.wsgi.register_view(APITemplateView)
hass.http.register_view(APIStatusView)
hass.http.register_view(APIEventStream)
hass.http.register_view(APIConfigView)
hass.http.register_view(APIDiscoveryView)
hass.http.register_view(APIStatesView)
hass.http.register_view(APIEntityStateView)
hass.http.register_view(APIEventListenersView)
hass.http.register_view(APIEventView)
hass.http.register_view(APIServicesView)
hass.http.register_view(APIDomainServicesView)
hass.http.register_view(APIEventForwardingView)
hass.http.register_view(APIComponentsView)
hass.http.register_view(APIErrorLogView)
hass.http.register_view(APITemplateView)

return True

Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/camera/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ def setup(hass, config):
component = EntityComponent(
logging.getLogger(__name__), DOMAIN, hass, SCAN_INTERVAL)

hass.wsgi.register_view(CameraImageView(hass, component.entities))
hass.wsgi.register_view(CameraMjpegStream(hass, component.entities))
hass.http.register_view(CameraImageView(hass, component.entities))
hass.http.register_view(CameraMjpegStream(hass, component.entities))

component.setup(config)

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/device_tracker/locative.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

def setup_scanner(hass, config, see):
"""Setup an endpoint for the Locative application."""
hass.wsgi.register_view(LocativeView(hass, see))
hass.http.register_view(LocativeView(hass, see))

return True

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/foursquare.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def checkin_user(call):
descriptions[DOMAIN][SERVICE_CHECKIN],
schema=CHECKIN_SERVICE_SCHEMA)

hass.wsgi.register_view(FoursquarePushReceiver(
hass.http.register_view(FoursquarePushReceiver(
hass, config[CONF_PUSH_SECRET]))

return True
Expand Down
26 changes: 13 additions & 13 deletions homeassistant/components/frontend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def register_built_in_panel(hass, component_name, sidebar_title=None,
# pylint: disable=too-many-arguments
path = 'panels/ha-panel-{}.html'.format(component_name)

if hass.wsgi.development:
if hass.http.development:
url = ('/static/home-assistant-polymer/panels/'
'{0}/ha-panel-{0}.html'.format(component_name))
else:
Expand Down Expand Up @@ -102,7 +102,7 @@ def register_panel(hass, component_name, path, md5=None, sidebar_title=None,
url = URL_PANEL_COMPONENT.format(component_name)

if url not in _REGISTERED_COMPONENTS:
hass.wsgi.register_static_path(url, path)
hass.http.register_static_path(url, path)
_REGISTERED_COMPONENTS.add(url)

fprinted_url = URL_PANEL_COMPONENT_FP.format(component_name, md5)
Expand All @@ -118,23 +118,23 @@ def add_manifest_json_key(key, val):

def setup(hass, config):
"""Setup serving the frontend."""
hass.wsgi.register_view(BootstrapView)
hass.wsgi.register_view(ManifestJSONView)
hass.http.register_view(BootstrapView)
hass.http.register_view(ManifestJSONView)

if hass.wsgi.development:
if hass.http.development:
sw_path = "home-assistant-polymer/build/service_worker.js"
else:
sw_path = "service_worker.js"

hass.wsgi.register_static_path("/service_worker.js",
hass.http.register_static_path("/service_worker.js",
os.path.join(STATIC_PATH, sw_path), 0)
hass.wsgi.register_static_path("/robots.txt",
hass.http.register_static_path("/robots.txt",
os.path.join(STATIC_PATH, "robots.txt"))
hass.wsgi.register_static_path("/static", STATIC_PATH)
hass.http.register_static_path("/static", STATIC_PATH)

local = hass.config.path('www')
if os.path.isdir(local):
hass.wsgi.register_static_path("/local", local)
hass.http.register_static_path("/local", local)

register_built_in_panel(hass, 'map', 'Map', 'mdi:account-location')

Expand All @@ -147,7 +147,7 @@ def register_frontend_index(event):
Done when Home Assistant is started so that all panels are known.
"""
hass.wsgi.register_view(IndexView(
hass.http.register_view(IndexView(
hass, ['/{}'.format(name) for name in PANELS]))

hass.bus.listen_once(EVENT_HOMEASSISTANT_START, register_frontend_index)
Expand Down Expand Up @@ -204,7 +204,7 @@ def __init__(self, hass, extra_urls):
@asyncio.coroutine
def get(self, request, entity_id=None):
"""Serve the index view."""
if self.hass.wsgi.development:
if self.hass.http.development:
core_url = '/static/home-assistant-polymer/build/core.js'
ui_url = '/static/home-assistant-polymer/src/home-assistant.html'
else:
Expand All @@ -224,8 +224,8 @@ def get(self, request, entity_id=None):
if self.hass.config.api.api_password:
# require password if set
no_auth = 'false'
if self.hass.wsgi.is_trusted_ip(
self.hass.wsgi.get_real_ip(request)):
if self.hass.http.is_trusted_ip(
self.hass.http.get_real_ip(request)):
# bypass for trusted networks
no_auth = 'true'

Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ def setup(hass, config):
filters.included_entities = include[CONF_ENTITIES]
filters.included_domains = include[CONF_DOMAINS]

hass.wsgi.register_view(Last5StatesView(hass))
hass.wsgi.register_view(HistoryPeriodView(hass, filters))
hass.http.register_view(Last5StatesView(hass))
hass.http.register_view(HistoryPeriodView(hass, filters))
register_built_in_panel(hass, 'history', 'History', 'mdi:poll-box')

return True
Expand Down
18 changes: 10 additions & 8 deletions homeassistant/components/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ def __init__(self, hass):

def filter(self, record):
"""Hide sensitive data in messages."""
if self.hass.wsgi.api_password is None:
if self.hass.http.api_password is None:
return True

record.msg = record.msg.replace(self.hass.wsgi.api_password, '*******')
record.msg = record.msg.replace(self.hass.http.api_password, '*******')

return True

Expand Down Expand Up @@ -155,7 +155,7 @@ def start_server(event):

hass.bus.listen_once(EVENT_HOMEASSISTANT_START, start_server)

hass.wsgi = server
hass.http = server
hass.config.api = rem.API(server_host if server_host != '0.0.0.0'
else util.get_local_ip(),
api_password, server_port,
Expand Down Expand Up @@ -378,12 +378,13 @@ def get_real_ip(request):
def is_trusted_ip(self, remote_addr):
"""Match an ip address against trusted CIDR networks."""
return any(ip_address(remote_addr) in trusted_network
for trusted_network in self.hass.wsgi.trusted_networks)
for trusted_network in self.hass.http.trusted_networks)


class HomeAssistantView(object):
"""Base view for all views."""

url = None
extra_urls = []
requires_auth = True # Views inheriting from this class can override this

Expand Down Expand Up @@ -421,6 +422,7 @@ def file(self, request, fil): # pylint: disable=no-self-use

def register(self, router):
"""Register the view with a router."""
assert self.url is not None, 'No url set for view'
urls = [self.url] + self.extra_urls

for method in ('get', 'post', 'delete', 'put'):
Expand Down Expand Up @@ -454,19 +456,19 @@ def handle(request):
# Auth code verbose on purpose
authenticated = False

if view.hass.wsgi.api_password is None:
if view.hass.http.api_password is None:
authenticated = True

elif view.hass.wsgi.is_trusted_ip(remote_addr):
elif view.hass.http.is_trusted_ip(remote_addr):
authenticated = True

elif hmac.compare_digest(request.headers.get(HTTP_HEADER_HA_AUTH, ''),
view.hass.wsgi.api_password):
view.hass.http.api_password):
# A valid auth header has been set
authenticated = True

elif hmac.compare_digest(request.GET.get(DATA_API_PASSWORD, ''),
view.hass.wsgi.api_password):
view.hass.http.api_password):
authenticated = True

if view.requires_auth and not authenticated:
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/ios.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,13 @@ def setup(hass, config):

discovery.load_platform(hass, "sensor", DOMAIN, {}, config)

hass.wsgi.register_view(iOSIdentifyDeviceView(hass))
hass.http.register_view(iOSIdentifyDeviceView(hass))

if config.get(DOMAIN) is not None:
app_config = config[DOMAIN]
if app_config.get(CONF_PUSH) is not None:
push_config = app_config[CONF_PUSH]
hass.wsgi.register_view(iOSPushConfigView(hass, push_config))
hass.http.register_view(iOSPushConfigView(hass, push_config))

return True

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/logbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def log_message(service):
message = message.async_render()
async_log_entry(hass, name, message, domain, entity_id)

hass.wsgi.register_view(LogbookView(hass, config))
hass.http.register_view(LogbookView(hass, config))

register_built_in_panel(hass, 'logbook', 'Logbook',
'mdi:format-list-bulleted-type')
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/media_player/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def setup(hass, config):
component = EntityComponent(
logging.getLogger(__name__), DOMAIN, hass, SCAN_INTERVAL)

hass.wsgi.register_view(MediaPlayerImageView(hass, component.entities))
hass.http.register_view(MediaPlayerImageView(hass, component.entities))

component.setup(config)

Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/notify/html5.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ def get_service(hass, config):
if registrations is None:
return None

hass.wsgi.register_view(
hass.http.register_view(
HTML5PushRegistrationView(hass, registrations, json_path))
hass.wsgi.register_view(HTML5PushCallbackView(hass, registrations))
hass.http.register_view(HTML5PushCallbackView(hass, registrations))

gcm_api_key = config.get(ATTR_GCM_API_KEY)
gcm_sender_id = config.get(ATTR_GCM_SENDER_ID)
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/sensor/fitbit.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
scope=['activity', 'heartrate', 'nutrition', 'profile',
'settings', 'sleep', 'weight'])

hass.wsgi.register_redirect(FITBIT_AUTH_START, fitbit_auth_start_url)
hass.wsgi.register_view(FitbitAuthCallbackView(
hass.http.register_redirect(FITBIT_AUTH_START, fitbit_auth_start_url)
hass.http.register_view(FitbitAuthCallbackView(
hass, config, add_devices, oauth))

request_oauth_completion(hass)
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/sensor/torque.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
email = config.get(CONF_EMAIL)
sensors = {}

hass.wsgi.register_view(TorqueReceiveDataView(
hass.http.register_view(TorqueReceiveDataView(
hass, email, vehicle, sensors, add_devices))
return True

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/switch/netio.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
port = config.get(CONF_PORT)

if len(DEVICES) == 0:
hass.wsgi.register_view(NetioApiView)
hass.http.register_view(NetioApiView)

dev = Netio(host, port, username, password)

Expand Down
8 changes: 4 additions & 4 deletions tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,19 +198,19 @@ def mock_state_change_event(hass, new_state, old_state=None):

def mock_http_component(hass):
"""Mock the HTTP component."""
hass.wsgi = mock.MagicMock()
hass.http = mock.MagicMock()
hass.config.components.append('http')
hass.wsgi.views = {}
hass.http.views = {}

def mock_register_view(view):
"""Store registered view."""
if isinstance(view, type):
# Instantiate the view, if needed
view = view(hass)

hass.wsgi.views[view.name] = view
hass.http.views[view.name] = view

hass.wsgi.register_view = mock_register_view
hass.http.register_view = mock_register_view


def mock_mqtt_component(hass):
Expand Down
4 changes: 2 additions & 2 deletions tests/components/camera/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def setup_platform():

yield from hass.loop.run_in_executor(None, setup_platform)

client = yield from test_client(hass.wsgi.app)
client = yield from test_client(hass.http.app)

resp = yield from client.get('/api/camera_proxy/camera.config_test')

Expand Down Expand Up @@ -57,7 +57,7 @@ def setup_platform():

yield from hass.loop.run_in_executor(None, setup_platform)

client = yield from test_client(hass.wsgi.app)
client = yield from test_client(hass.http.app)

resp = yield from client.get('/api/camera_proxy/camera.config_test')

Expand Down
2 changes: 1 addition & 1 deletion tests/components/camera/test_local_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def setup_platform():

yield from hass.loop.run_in_executor(None, setup_platform)

client = yield from test_client(hass.wsgi.app)
client = yield from test_client(hass.http.app)

m_open = mock.mock_open(read_data=test_string.encode('utf-8'))
with mock.patch(
Expand Down
2 changes: 1 addition & 1 deletion tests/components/camera/test_uvc.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class TestUVCSetup(unittest.TestCase):
def setUp(self):
"""Setup things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.hass.wsgi = mock.MagicMock()
self.hass.http = mock.MagicMock()
self.hass.config.components = ['http']

def tearDown(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/components/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def setUpModule():

bootstrap.setup_component(hass, 'api')

hass.wsgi.trusted_networks = [
hass.http.trusted_networks = [
ip_network(trusted_network)
for trusted_network in TRUSTED_NETWORKS]

Expand Down

0 comments on commit db9b7e8

Please sign in to comment.