mirror of
https://github.com/elisspace/core.git
synced 2026-10-05 16:56:19 +00:00
Cloud cognito switch (#10823)
* Allow email based cognito instance * Fix quitting Home Assistant while reconnecting * Lint
This commit is contained in:
committed by
Pascal Vizeli
parent
1b7a64412d
commit
fe0a9529ed
@@ -104,6 +104,11 @@ class Cloud:
|
||||
self.region = info['region']
|
||||
self.relayer = info['relayer']
|
||||
|
||||
@property
|
||||
def cognito_email_based(self):
|
||||
"""Return if cognito is email based."""
|
||||
return not self.user_pool_id.endswith('GmV')
|
||||
|
||||
@property
|
||||
def is_logged_in(self):
|
||||
"""Get if cloud is logged in."""
|
||||
|
||||
@@ -69,7 +69,10 @@ def register(cloud, email, password):
|
||||
|
||||
cognito = _cognito(cloud)
|
||||
try:
|
||||
cognito.register(_generate_username(email), password, email=email)
|
||||
if cloud.cognito_email_based:
|
||||
cognito.register(email, password, email=email)
|
||||
else:
|
||||
cognito.register(_generate_username(email), password, email=email)
|
||||
except ClientError as err:
|
||||
raise _map_aws_exception(err)
|
||||
|
||||
@@ -80,7 +83,11 @@ def confirm_register(cloud, confirmation_code, email):
|
||||
|
||||
cognito = _cognito(cloud)
|
||||
try:
|
||||
cognito.confirm_sign_up(confirmation_code, _generate_username(email))
|
||||
if cloud.cognito_email_based:
|
||||
cognito.confirm_sign_up(confirmation_code, email)
|
||||
else:
|
||||
cognito.confirm_sign_up(confirmation_code,
|
||||
_generate_username(email))
|
||||
except ClientError as err:
|
||||
raise _map_aws_exception(err)
|
||||
|
||||
@@ -89,7 +96,11 @@ def forgot_password(cloud, email):
|
||||
"""Initiate forgotten password flow."""
|
||||
from botocore.exceptions import ClientError
|
||||
|
||||
cognito = _cognito(cloud, username=_generate_username(email))
|
||||
if cloud.cognito_email_based:
|
||||
cognito = _cognito(cloud, username=email)
|
||||
else:
|
||||
cognito = _cognito(cloud, username=_generate_username(email))
|
||||
|
||||
try:
|
||||
cognito.initiate_forgot_password()
|
||||
except ClientError as err:
|
||||
@@ -100,7 +111,11 @@ def confirm_forgot_password(cloud, confirmation_code, email, new_password):
|
||||
"""Confirm forgotten password code and change password."""
|
||||
from botocore.exceptions import ClientError
|
||||
|
||||
cognito = _cognito(cloud, username=_generate_username(email))
|
||||
if cloud.cognito_email_based:
|
||||
cognito = _cognito(cloud, username=email)
|
||||
else:
|
||||
cognito = _cognito(cloud, username=_generate_username(email))
|
||||
|
||||
try:
|
||||
cognito.confirm_forgot_password(confirmation_code, new_password)
|
||||
except ClientError as err:
|
||||
|
||||
@@ -59,13 +59,6 @@ class CloudIoT:
|
||||
if self.state == STATE_CONNECTED:
|
||||
raise RuntimeError('Already connected')
|
||||
|
||||
self.state = STATE_CONNECTING
|
||||
self.close_requested = False
|
||||
remove_hass_stop_listener = None
|
||||
session = async_get_clientsession(self.cloud.hass)
|
||||
client = None
|
||||
disconnect_warn = None
|
||||
|
||||
@asyncio.coroutine
|
||||
def _handle_hass_stop(event):
|
||||
"""Handle Home Assistant shutting down."""
|
||||
@@ -73,6 +66,14 @@ class CloudIoT:
|
||||
remove_hass_stop_listener = None
|
||||
yield from self.disconnect()
|
||||
|
||||
self.state = STATE_CONNECTING
|
||||
self.close_requested = False
|
||||
remove_hass_stop_listener = hass.bus.async_listen_once(
|
||||
EVENT_HOMEASSISTANT_STOP, _handle_hass_stop)
|
||||
session = async_get_clientsession(self.cloud.hass)
|
||||
client = None
|
||||
disconnect_warn = None
|
||||
|
||||
try:
|
||||
yield from hass.async_add_job(auth_api.check_token, self.cloud)
|
||||
|
||||
@@ -83,9 +84,6 @@ class CloudIoT:
|
||||
})
|
||||
self.tries = 0
|
||||
|
||||
remove_hass_stop_listener = hass.bus.async_listen_once(
|
||||
EVENT_HOMEASSISTANT_STOP, _handle_hass_stop)
|
||||
|
||||
_LOGGER.info('Connected')
|
||||
self.state = STATE_CONNECTED
|
||||
|
||||
|
||||
Reference in New Issue
Block a user