Skip to content

Commit

Permalink
Remove setup_schema from MFA base class
Browse files Browse the repository at this point in the history
  • Loading branch information
awarecan committed Aug 24, 2018
1 parent af963a3 commit 39df36f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 19 deletions.
7 changes: 0 additions & 7 deletions homeassistant/auth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,6 @@ async def async_enable_user_mfa(self, user: models.User,
raise ValueError('Unable find multi-factor auth module: {}'
.format(mfa_module_id))

if module.setup_schema is not None:
try:
# pylint: disable=not-callable
data = module.setup_schema(data)
except vol.Invalid as err:
raise ValueError('Data does not match schema: {}'.format(err))

await module.async_setup_user(user.id, data)

async def async_disable_user_mfa(self, user: models.User,
Expand Down
14 changes: 4 additions & 10 deletions homeassistant/auth/mfa_modules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,12 @@ def input_schema(self) -> vol.Schema:
"""Return a voluptuous schema to define mfa auth module's input."""
raise NotImplementedError

@property
def setup_schema(self) -> Optional[vol.Schema]:
"""Return a vol schema to validate mfa auth module's setup input.
Optional
"""
return None

async def async_setup_flow(self, user_id: str) -> 'SetupFlow':
"""Return a data entry flow handler for setup module.
Mfa module should extend SetupFlow
"""
return SetupFlow(self, user_id)
return SetupFlow(self, vol.Schema({}), user_id)

async def async_setup_user(self, user_id: str, setup_data: Any) -> Any:
"""Set up user for mfa auth module."""
Expand All @@ -101,9 +93,11 @@ class SetupFlow(data_entry_flow.FlowHandler):
"""Handler for the setup flow."""

def __init__(self, auth_module: MultiFactorAuthModule,
setup_schema: vol.Schema,
user_id: str) -> None:
"""Initialize the setup flow."""
self._auth_module = auth_module
self._setup_schema = setup_schema
self._user_id = user_id

async def async_step_init(
Expand All @@ -126,7 +120,7 @@ async def async_step_init(

return self.async_show_form(
step_id='init',
data_schema=self._auth_module.setup_schema,
data_schema=self._setup_schema,
errors=errors
)

Expand Down
11 changes: 9 additions & 2 deletions homeassistant/auth/mfa_modules/insecure_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from homeassistant.core import HomeAssistant

from . import MultiFactorAuthModule, MULTI_FACTOR_AUTH_MODULES, \
MULTI_FACTOR_AUTH_MODULE_SCHEMA
MULTI_FACTOR_AUTH_MODULE_SCHEMA, SetupFlow

CONFIG_SCHEMA = MULTI_FACTOR_AUTH_MODULE_SCHEMA.extend({
vol.Required('data'): [vol.Schema({
Expand Down Expand Up @@ -36,10 +36,17 @@ def input_schema(self) -> vol.Schema:
return vol.Schema({'pin': str})

@property
def setup_schema(self) -> Optional[vol.Schema]:
def setup_schema(self) -> vol.Schema:
"""Validate async_setup_user input data."""
return vol.Schema({'pin': str})

async def async_setup_flow(self, user_id: str) -> SetupFlow:
"""Return a data entry flow handler for setup module.
Mfa module should extend SetupFlow
"""
return SetupFlow(self, self.setup_schema, user_id)

async def async_setup_user(self, user_id: str, setup_data: Any) -> Any:
"""Set up user to use mfa module."""
# data shall has been validate in caller
Expand Down

0 comments on commit 39df36f

Please sign in to comment.