From 6a411710dfe84094182146e973a194a89ef931fb Mon Sep 17 00:00:00 2001 From: Jason Hu Date: Tue, 2 Apr 2019 21:23:59 -0700 Subject: [PATCH] Fix trusted networks auth provider warning message (#22671) * Fix trusted networks auth provider warning message * Update auth.py --- homeassistant/components/http/auth.py | 16 ++++++++++------ homeassistant/components/http/view.py | 2 ++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/http/auth.py b/homeassistant/components/http/auth.py index 7b8508894ce..0d8e327e086 100644 --- a/homeassistant/components/http/auth.py +++ b/homeassistant/components/http/auth.py @@ -190,12 +190,16 @@ def setup_auth(hass, app): elif (trusted_networks and await async_validate_trusted_networks(request)): - _LOGGER.warning( - 'Access from trusted networks without auth token is going to ' - 'be removed in Home Assistant 0.96. Configure the trusted ' - 'networks auth provider or use long-lived access tokens to ' - 'access %s from %s', - request.path, request[KEY_REAL_IP]) + if request.path not in old_auth_warning: + # When removing this, don't forget to remove the print logic + # in http/view.py + request['deprecate_warning_message'] = \ + 'Access from trusted networks without auth token is ' \ + 'going to be removed in Home Assistant 0.96. Configure ' \ + 'the trusted networks auth provider or use long-lived ' \ + 'access tokens to access {} from {}'.format( + request.path, request[KEY_REAL_IP]) + old_auth_warning.add(request.path) authenticated = True elif (support_legacy and HTTP_HEADER_HA_AUTH in request.headers and diff --git a/homeassistant/components/http/view.py b/homeassistant/components/http/view.py index d68cabebacf..8d5e0ee88b1 100644 --- a/homeassistant/components/http/view.py +++ b/homeassistant/components/http/view.py @@ -98,6 +98,8 @@ def request_handler_factory(view, handler): if view.requires_auth: if authenticated: + if 'deprecate_warning_message' in request: + _LOGGER.warning(request['deprecate_warning_message']) await process_success_login(request) else: raise HTTPUnauthorized()