Migrate auth to use async_import_module to avoid blocking I/O in the event loop (#113387)
parent
4aec48d358
commit
4341b21a61
|
@ -2,7 +2,6 @@
|
|||
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib
|
||||
import logging
|
||||
import types
|
||||
from typing import Any
|
||||
|
@ -15,6 +14,7 @@ from homeassistant.const import CONF_ID, CONF_NAME, CONF_TYPE
|
|||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResult
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.importlib import async_import_module
|
||||
from homeassistant.util.decorator import Registry
|
||||
|
||||
MULTI_FACTOR_AUTH_MODULES: Registry[str, type[MultiFactorAuthModule]] = Registry()
|
||||
|
@ -149,7 +149,7 @@ async def _load_mfa_module(hass: HomeAssistant, module_name: str) -> types.Modul
|
|||
module_path = f"homeassistant.auth.mfa_modules.{module_name}"
|
||||
|
||||
try:
|
||||
module = importlib.import_module(module_path)
|
||||
module = await async_import_module(hass, module_path)
|
||||
except ImportError as err:
|
||||
_LOGGER.error("Unable to load mfa module %s: %s", module_name, err)
|
||||
raise HomeAssistantError(
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Mapping
|
||||
import importlib
|
||||
import logging
|
||||
import types
|
||||
from typing import Any
|
||||
|
@ -15,6 +14,7 @@ from homeassistant import data_entry_flow, requirements
|
|||
from homeassistant.const import CONF_ID, CONF_NAME, CONF_TYPE
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.importlib import async_import_module
|
||||
from homeassistant.util import dt as dt_util
|
||||
from homeassistant.util.decorator import Registry
|
||||
|
||||
|
@ -157,7 +157,9 @@ async def load_auth_provider_module(
|
|||
) -> types.ModuleType:
|
||||
"""Load an auth provider."""
|
||||
try:
|
||||
module = importlib.import_module(f"homeassistant.auth.providers.{provider}")
|
||||
module = await async_import_module(
|
||||
hass, f"homeassistant.auth.providers.{provider}"
|
||||
)
|
||||
except ImportError as err:
|
||||
_LOGGER.error("Unable to load auth provider %s: %s", provider, err)
|
||||
raise HomeAssistantError(
|
||||
|
|
|
@ -41,6 +41,7 @@ async def test_validating_password_invalid_user(data, hass: HomeAssistant) -> No
|
|||
async def test_not_allow_set_id() -> None:
|
||||
"""Test we are not allowed to set an ID in config."""
|
||||
hass = Mock()
|
||||
hass.data = {}
|
||||
with pytest.raises(vol.Invalid):
|
||||
await auth_provider_from_config(
|
||||
hass, None, {"type": "homeassistant", "id": "invalid"}
|
||||
|
|
Loading…
Reference in New Issue