Add verify ssl option to paperless-ngx integration (#146802)
* add verify ssl config option * Refactoring * Use .get() with default value instead of migration * Reconfigure fix * minor changespull/138648/merge
parent
61b00892c3
commit
c335b5b37c
|
@ -9,7 +9,7 @@ from pypaperless.exceptions import (
|
|||
PaperlessInvalidTokenError,
|
||||
)
|
||||
|
||||
from homeassistant.const import CONF_API_KEY, CONF_URL, Platform
|
||||
from homeassistant.const import CONF_API_KEY, CONF_URL, CONF_VERIFY_SSL, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import (
|
||||
ConfigEntryAuthFailed,
|
||||
|
@ -69,7 +69,7 @@ async def _get_paperless_api(
|
|||
api = Paperless(
|
||||
entry.data[CONF_URL],
|
||||
entry.data[CONF_API_KEY],
|
||||
session=async_get_clientsession(hass),
|
||||
session=async_get_clientsession(hass, entry.data.get(CONF_VERIFY_SSL, True)),
|
||||
)
|
||||
|
||||
try:
|
||||
|
|
|
@ -16,7 +16,7 @@ from pypaperless.exceptions import (
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
|
||||
from homeassistant.const import CONF_API_KEY, CONF_URL
|
||||
from homeassistant.const import CONF_API_KEY, CONF_URL, CONF_VERIFY_SSL
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
|
||||
from .const import DOMAIN, LOGGER
|
||||
|
@ -25,6 +25,7 @@ STEP_USER_DATA_SCHEMA = vol.Schema(
|
|||
{
|
||||
vol.Required(CONF_URL): str,
|
||||
vol.Required(CONF_API_KEY): str,
|
||||
vol.Required(CONF_VERIFY_SSL, default=True): bool,
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -78,15 +79,19 @@ class PaperlessConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
if not errors:
|
||||
return self.async_update_reload_and_abort(entry, data=user_input)
|
||||
|
||||
if user_input is not None:
|
||||
suggested_values = user_input
|
||||
else:
|
||||
suggested_values = {
|
||||
CONF_URL: entry.data[CONF_URL],
|
||||
CONF_VERIFY_SSL: entry.data.get(CONF_VERIFY_SSL, True),
|
||||
}
|
||||
|
||||
return self.async_show_form(
|
||||
step_id="reconfigure",
|
||||
data_schema=self.add_suggested_values_to_schema(
|
||||
data_schema=STEP_USER_DATA_SCHEMA,
|
||||
suggested_values={
|
||||
CONF_URL: user_input[CONF_URL]
|
||||
if user_input is not None
|
||||
else entry.data[CONF_URL],
|
||||
},
|
||||
suggested_values=suggested_values,
|
||||
),
|
||||
errors=errors,
|
||||
)
|
||||
|
@ -122,13 +127,15 @@ class PaperlessConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
errors=errors,
|
||||
)
|
||||
|
||||
async def _validate_input(self, user_input: dict[str, str]) -> dict[str, str]:
|
||||
async def _validate_input(self, user_input: dict[str, Any]) -> dict[str, str]:
|
||||
errors: dict[str, str] = {}
|
||||
|
||||
client = Paperless(
|
||||
user_input[CONF_URL],
|
||||
user_input[CONF_API_KEY],
|
||||
session=async_get_clientsession(self.hass),
|
||||
session=async_get_clientsession(
|
||||
self.hass, user_input.get(CONF_VERIFY_SSL, True)
|
||||
),
|
||||
)
|
||||
|
||||
try:
|
||||
|
|
|
@ -4,11 +4,13 @@
|
|||
"user": {
|
||||
"data": {
|
||||
"url": "[%key:common::config_flow::data::url%]",
|
||||
"api_key": "[%key:common::config_flow::data::api_key%]"
|
||||
"api_key": "[%key:common::config_flow::data::api_key%]",
|
||||
"verify_ssl": "[%key:common::config_flow::data::verify_ssl%]"
|
||||
},
|
||||
"data_description": {
|
||||
"url": "URL to connect to the Paperless-ngx instance",
|
||||
"api_key": "API key to connect to the Paperless-ngx API"
|
||||
"api_key": "API key to connect to the Paperless-ngx API",
|
||||
"verify_ssl": "Verify the SSL certificate of the Paperless-ngx instance. Disable this option if you’re using a self-signed certificate."
|
||||
},
|
||||
"title": "Add Paperless-ngx instance"
|
||||
},
|
||||
|
@ -24,11 +26,13 @@
|
|||
"reconfigure": {
|
||||
"data": {
|
||||
"url": "[%key:common::config_flow::data::url%]",
|
||||
"api_key": "[%key:common::config_flow::data::api_key%]"
|
||||
"api_key": "[%key:common::config_flow::data::api_key%]",
|
||||
"verify_ssl": "[%key:common::config_flow::data::verify_ssl%]"
|
||||
},
|
||||
"data_description": {
|
||||
"url": "[%key:component::paperless_ngx::config::step::user::data_description::url%]",
|
||||
"api_key": "[%key:component::paperless_ngx::config::step::user::data_description::api_key%]"
|
||||
"api_key": "[%key:component::paperless_ngx::config::step::user::data_description::api_key%]",
|
||||
"verify_ssl": "[%key:component::paperless_ngx::config::step::user::data_description::verify_ssl%]"
|
||||
},
|
||||
"title": "Reconfigure Paperless-ngx instance"
|
||||
}
|
||||
|
|
|
@ -1,15 +1,17 @@
|
|||
"""Constants for the Paperless NGX integration tests."""
|
||||
|
||||
from homeassistant.const import CONF_API_KEY, CONF_URL
|
||||
from homeassistant.const import CONF_API_KEY, CONF_URL, CONF_VERIFY_SSL
|
||||
|
||||
USER_INPUT_ONE = {
|
||||
CONF_URL: "https://192.168.69.16:8000",
|
||||
CONF_API_KEY: "12345678",
|
||||
CONF_VERIFY_SSL: True,
|
||||
}
|
||||
|
||||
USER_INPUT_TWO = {
|
||||
CONF_URL: "https://paperless.example.de",
|
||||
CONF_API_KEY: "87654321",
|
||||
CONF_VERIFY_SSL: True,
|
||||
}
|
||||
|
||||
USER_INPUT_REAUTH = {CONF_API_KEY: "192837465"}
|
||||
|
|
Loading…
Reference in New Issue