2020-02-21 17:55:41 +01:00
|
|
|
"""Init file for Supervisor RESTful API."""
|
2017-03-30 16:01:52 +02:00
|
|
|
import logging
|
2017-05-13 17:41:46 +02:00
|
|
|
from pathlib import Path
|
2019-03-27 17:20:05 +01:00
|
|
|
from typing import Optional
|
2017-03-30 16:01:52 +02:00
|
|
|
|
|
|
|
from aiohttp import web
|
|
|
|
|
2019-03-27 17:20:05 +01:00
|
|
|
from ..coresys import CoreSys, CoreSysAttributes
|
2017-04-12 22:59:40 +02:00
|
|
|
from .addons import APIAddons
|
2020-03-27 17:37:48 +01:00
|
|
|
from .audio import APIAudio
|
2018-10-12 12:21:48 +02:00
|
|
|
from .auth import APIAuth
|
2021-07-27 10:06:09 +02:00
|
|
|
from .backups import APIBackups
|
2020-03-27 17:37:48 +01:00
|
|
|
from .cli import APICli
|
2018-02-08 17:19:47 +01:00
|
|
|
from .discovery import APIDiscovery
|
2019-08-13 14:20:42 +02:00
|
|
|
from .dns import APICoreDNS
|
2020-10-05 12:19:25 +02:00
|
|
|
from .docker import APIDocker
|
2018-04-12 22:15:08 +02:00
|
|
|
from .hardware import APIHardware
|
2019-03-27 17:20:05 +01:00
|
|
|
from .homeassistant import APIHomeAssistant
|
|
|
|
from .host import APIHost
|
2019-04-05 12:13:44 +02:00
|
|
|
from .ingress import APIIngress
|
2020-11-24 10:54:57 +01:00
|
|
|
from .jobs import APIJobs
|
2021-06-14 10:05:37 +02:00
|
|
|
from .middleware.security import SecurityMiddleware
|
2020-05-21 13:30:54 +02:00
|
|
|
from .multicast import APIMulticast
|
2020-08-24 16:58:02 +02:00
|
|
|
from .network import APINetwork
|
2020-09-11 16:05:57 +02:00
|
|
|
from .observer import APIObserver
|
2020-05-21 13:30:54 +02:00
|
|
|
from .os import APIOS
|
2017-12-26 00:51:07 +01:00
|
|
|
from .proxy import APIProxy
|
2020-10-13 12:54:17 +02:00
|
|
|
from .resolution import APIResoulution
|
2022-01-24 10:32:23 +01:00
|
|
|
from .root import APIRoot
|
2021-05-10 14:27:50 +02:00
|
|
|
from .security import APISecurity
|
2019-03-27 17:20:05 +01:00
|
|
|
from .services import APIServices
|
2021-02-25 16:15:51 +01:00
|
|
|
from .store import APIStore
|
2019-03-27 17:20:05 +01:00
|
|
|
from .supervisor import APISupervisor
|
2017-03-30 16:01:52 +02:00
|
|
|
|
2019-08-22 12:48:02 +02:00
|
|
|
_LOGGER: logging.Logger = logging.getLogger(__name__)
|
2017-03-30 16:01:52 +02:00
|
|
|
|
|
|
|
|
2022-02-10 14:13:40 +01:00
|
|
|
MAX_CLIENT_SIZE: int = 1024**2 * 16
|
2020-01-09 10:16:20 +01:00
|
|
|
|
|
|
|
|
2018-01-02 21:21:29 +01:00
|
|
|
class RestAPI(CoreSysAttributes):
|
2020-02-21 17:55:41 +01:00
|
|
|
"""Handle RESTful API for Supervisor."""
|
2017-03-30 16:01:52 +02:00
|
|
|
|
2019-03-27 17:20:05 +01:00
|
|
|
def __init__(self, coresys: CoreSys):
|
2018-09-18 23:47:47 +02:00
|
|
|
"""Initialize Docker base wrapper."""
|
2019-03-27 17:20:05 +01:00
|
|
|
self.coresys: CoreSys = coresys
|
|
|
|
self.security: SecurityMiddleware = SecurityMiddleware(coresys)
|
|
|
|
self.webapp: web.Application = web.Application(
|
2020-01-09 10:16:20 +01:00
|
|
|
client_max_size=MAX_CLIENT_SIZE,
|
2020-10-12 15:56:29 +02:00
|
|
|
middlewares=[
|
|
|
|
self.security.system_validation,
|
|
|
|
self.security.token_validation,
|
|
|
|
],
|
2019-05-27 12:35:06 +02:00
|
|
|
)
|
2017-03-30 16:01:52 +02:00
|
|
|
|
2017-03-30 23:26:26 +02:00
|
|
|
# service stuff
|
2019-03-27 17:20:05 +01:00
|
|
|
self._runner: web.AppRunner = web.AppRunner(self.webapp)
|
|
|
|
self._site: Optional[web.TCPSite] = None
|
2017-03-30 16:01:52 +02:00
|
|
|
|
2019-03-27 17:20:05 +01:00
|
|
|
async def load(self) -> None:
|
2018-01-02 21:21:29 +01:00
|
|
|
"""Register REST API Calls."""
|
2020-10-06 11:26:56 +02:00
|
|
|
self._register_addons()
|
|
|
|
self._register_audio()
|
|
|
|
self._register_auth()
|
2021-07-27 10:06:09 +02:00
|
|
|
self._register_backups()
|
2020-03-27 17:37:48 +01:00
|
|
|
self._register_cli()
|
2020-10-06 11:26:56 +02:00
|
|
|
self._register_discovery()
|
|
|
|
self._register_dns()
|
|
|
|
self._register_docker()
|
2018-04-12 22:15:08 +02:00
|
|
|
self._register_hardware()
|
2018-01-02 21:21:29 +01:00
|
|
|
self._register_homeassistant()
|
2020-10-06 11:26:56 +02:00
|
|
|
self._register_host()
|
2022-01-24 10:32:23 +01:00
|
|
|
self._register_root()
|
2019-04-05 12:13:44 +02:00
|
|
|
self._register_ingress()
|
2020-10-06 11:26:56 +02:00
|
|
|
self._register_multicast()
|
|
|
|
self._register_network()
|
|
|
|
self._register_observer()
|
|
|
|
self._register_os()
|
2020-11-24 10:54:57 +01:00
|
|
|
self._register_jobs()
|
2020-10-06 11:26:56 +02:00
|
|
|
self._register_panel()
|
|
|
|
self._register_proxy()
|
2020-10-13 12:54:17 +02:00
|
|
|
self._register_resolution()
|
2018-02-08 17:19:47 +01:00
|
|
|
self._register_services()
|
2020-10-06 11:26:56 +02:00
|
|
|
self._register_supervisor()
|
2021-02-25 16:15:51 +01:00
|
|
|
self._register_store()
|
2021-05-10 14:27:50 +02:00
|
|
|
self._register_security()
|
2018-01-02 21:21:29 +01:00
|
|
|
|
2020-10-23 16:48:03 +02:00
|
|
|
await self.start()
|
|
|
|
|
2019-03-27 17:20:05 +01:00
|
|
|
def _register_host(self) -> None:
|
2018-09-18 23:47:47 +02:00
|
|
|
"""Register hostcontrol functions."""
|
2018-01-02 21:21:29 +01:00
|
|
|
api_host = APIHost()
|
|
|
|
api_host.coresys = self.coresys
|
2017-03-30 16:01:52 +02:00
|
|
|
|
2019-05-27 12:35:06 +02:00
|
|
|
self.webapp.add_routes(
|
|
|
|
[
|
|
|
|
web.get("/host/info", api_host.info),
|
2020-03-28 15:56:57 +01:00
|
|
|
web.get("/host/logs", api_host.logs),
|
2019-05-27 12:35:06 +02:00
|
|
|
web.post("/host/reboot", api_host.reboot),
|
|
|
|
web.post("/host/shutdown", api_host.shutdown),
|
|
|
|
web.post("/host/reload", api_host.reload),
|
|
|
|
web.post("/host/options", api_host.options),
|
|
|
|
web.get("/host/services", api_host.services),
|
|
|
|
web.post("/host/services/{service}/stop", api_host.service_stop),
|
|
|
|
web.post("/host/services/{service}/start", api_host.service_start),
|
|
|
|
web.post("/host/services/{service}/restart", api_host.service_restart),
|
|
|
|
web.post("/host/services/{service}/reload", api_host.service_reload),
|
|
|
|
]
|
|
|
|
)
|
2017-04-05 08:55:19 +02:00
|
|
|
|
2020-08-24 16:58:02 +02:00
|
|
|
def _register_network(self) -> None:
|
|
|
|
"""Register network functions."""
|
|
|
|
api_network = APINetwork()
|
|
|
|
api_network.coresys = self.coresys
|
|
|
|
|
|
|
|
self.webapp.add_routes(
|
|
|
|
[
|
|
|
|
web.get("/network/info", api_network.info),
|
2020-12-01 14:03:59 +01:00
|
|
|
web.post("/network/reload", api_network.reload),
|
2020-08-24 16:58:02 +02:00
|
|
|
web.get(
|
|
|
|
"/network/interface/{interface}/info", api_network.interface_info
|
|
|
|
),
|
|
|
|
web.post(
|
|
|
|
"/network/interface/{interface}/update",
|
|
|
|
api_network.interface_update,
|
|
|
|
),
|
2020-11-09 08:56:42 +01:00
|
|
|
web.get(
|
|
|
|
"/network/interface/{interface}/accesspoints",
|
|
|
|
api_network.scan_accesspoints,
|
|
|
|
),
|
|
|
|
web.post(
|
|
|
|
"/network/interface/{interface}/vlan/{vlan}",
|
|
|
|
api_network.create_vlan,
|
|
|
|
),
|
2020-08-24 16:58:02 +02:00
|
|
|
]
|
|
|
|
)
|
|
|
|
|
2020-03-27 17:37:48 +01:00
|
|
|
def _register_os(self) -> None:
|
|
|
|
"""Register OS functions."""
|
|
|
|
api_os = APIOS()
|
|
|
|
api_os.coresys = self.coresys
|
|
|
|
|
|
|
|
self.webapp.add_routes(
|
|
|
|
[
|
|
|
|
web.get("/os/info", api_os.info),
|
|
|
|
web.post("/os/update", api_os.update),
|
|
|
|
web.post("/os/config/sync", api_os.config_sync),
|
2021-09-17 15:01:07 +02:00
|
|
|
web.post("/os/datadisk/move", api_os.migrate_data),
|
2021-09-21 14:51:58 +02:00
|
|
|
web.get("/os/datadisk/list", api_os.list_data),
|
2020-03-27 17:37:48 +01:00
|
|
|
]
|
|
|
|
)
|
|
|
|
|
2021-05-10 14:27:50 +02:00
|
|
|
def _register_security(self) -> None:
|
|
|
|
"""Register Security functions."""
|
|
|
|
api_security = APISecurity()
|
|
|
|
api_security.coresys = self.coresys
|
|
|
|
|
|
|
|
self.webapp.add_routes(
|
|
|
|
[
|
|
|
|
web.get("/security/info", api_security.info),
|
|
|
|
web.post("/security/options", api_security.options),
|
2022-04-30 10:14:43 +02:00
|
|
|
web.post("/security/integrity", api_security.integrity_check),
|
2021-05-10 14:27:50 +02:00
|
|
|
]
|
|
|
|
)
|
|
|
|
|
2020-11-24 10:54:57 +01:00
|
|
|
def _register_jobs(self) -> None:
|
|
|
|
"""Register Jobs functions."""
|
|
|
|
api_jobs = APIJobs()
|
|
|
|
api_jobs.coresys = self.coresys
|
|
|
|
|
|
|
|
self.webapp.add_routes(
|
|
|
|
[
|
|
|
|
web.get("/jobs/info", api_jobs.info),
|
|
|
|
web.post("/jobs/options", api_jobs.options),
|
|
|
|
web.post("/jobs/reset", api_jobs.reset),
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
2020-03-27 17:37:48 +01:00
|
|
|
def _register_cli(self) -> None:
|
|
|
|
"""Register HA cli functions."""
|
|
|
|
api_cli = APICli()
|
|
|
|
api_cli.coresys = self.coresys
|
2018-06-22 22:54:03 +02:00
|
|
|
|
2019-05-27 12:35:06 +02:00
|
|
|
self.webapp.add_routes(
|
|
|
|
[
|
2020-03-27 17:37:48 +01:00
|
|
|
web.get("/cli/info", api_cli.info),
|
|
|
|
web.get("/cli/stats", api_cli.stats),
|
|
|
|
web.post("/cli/update", api_cli.update),
|
2019-05-27 12:35:06 +02:00
|
|
|
]
|
|
|
|
)
|
2018-06-22 22:54:03 +02:00
|
|
|
|
2020-09-11 16:05:57 +02:00
|
|
|
def _register_observer(self) -> None:
|
|
|
|
"""Register Observer functions."""
|
|
|
|
api_observer = APIObserver()
|
|
|
|
api_observer.coresys = self.coresys
|
|
|
|
|
|
|
|
self.webapp.add_routes(
|
|
|
|
[
|
|
|
|
web.get("/observer/info", api_observer.info),
|
|
|
|
web.get("/observer/stats", api_observer.stats),
|
|
|
|
web.post("/observer/update", api_observer.update),
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
2020-04-05 23:26:22 +02:00
|
|
|
def _register_multicast(self) -> None:
|
|
|
|
"""Register Multicast functions."""
|
|
|
|
api_multicast = APIMulticast()
|
|
|
|
api_multicast.coresys = self.coresys
|
|
|
|
|
|
|
|
self.webapp.add_routes(
|
|
|
|
[
|
|
|
|
web.get("/multicast/info", api_multicast.info),
|
|
|
|
web.get("/multicast/stats", api_multicast.stats),
|
2020-04-08 14:08:09 +02:00
|
|
|
web.get("/multicast/logs", api_multicast.logs),
|
2020-04-05 23:26:22 +02:00
|
|
|
web.post("/multicast/update", api_multicast.update),
|
|
|
|
web.post("/multicast/restart", api_multicast.restart),
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
2019-03-27 17:20:05 +01:00
|
|
|
def _register_hardware(self) -> None:
|
2018-09-18 23:47:47 +02:00
|
|
|
"""Register hardware functions."""
|
2018-04-12 22:15:08 +02:00
|
|
|
api_hardware = APIHardware()
|
|
|
|
api_hardware.coresys = self.coresys
|
|
|
|
|
2019-05-27 12:35:06 +02:00
|
|
|
self.webapp.add_routes(
|
|
|
|
[
|
|
|
|
web.get("/hardware/info", api_hardware.info),
|
|
|
|
web.get("/hardware/audio", api_hardware.audio),
|
|
|
|
]
|
|
|
|
)
|
2018-04-12 22:15:08 +02:00
|
|
|
|
2022-01-24 10:32:23 +01:00
|
|
|
def _register_root(self) -> None:
|
|
|
|
"""Register root functions."""
|
|
|
|
api_root = APIRoot()
|
|
|
|
api_root.coresys = self.coresys
|
|
|
|
|
|
|
|
self.webapp.add_routes([web.get("/info", api_root.info)])
|
|
|
|
self.webapp.add_routes([web.post("/refresh_updates", api_root.refresh_updates)])
|
|
|
|
self.webapp.add_routes(
|
|
|
|
[web.get("/available_updates", api_root.available_updates)]
|
|
|
|
)
|
2018-09-26 11:39:45 +02:00
|
|
|
|
2022-01-24 10:32:23 +01:00
|
|
|
# Remove 2023
|
|
|
|
self.webapp.add_routes(
|
|
|
|
[web.get("/supervisor/available_updates", api_root.available_updates)]
|
|
|
|
)
|
2018-09-26 11:39:45 +02:00
|
|
|
|
2020-10-13 12:54:17 +02:00
|
|
|
def _register_resolution(self) -> None:
|
|
|
|
"""Register info functions."""
|
|
|
|
api_resolution = APIResoulution()
|
|
|
|
api_resolution.coresys = self.coresys
|
|
|
|
|
2020-10-14 17:14:25 +02:00
|
|
|
self.webapp.add_routes(
|
|
|
|
[
|
2020-10-16 13:07:02 +02:00
|
|
|
web.get("/resolution/info", api_resolution.info),
|
2021-03-15 10:16:32 +01:00
|
|
|
web.post(
|
|
|
|
"/resolution/check/{check}/options", api_resolution.options_check
|
|
|
|
),
|
2021-03-15 10:33:06 +01:00
|
|
|
web.post("/resolution/check/{check}/run", api_resolution.run_check),
|
2020-10-14 17:14:25 +02:00
|
|
|
web.post(
|
2020-10-16 12:22:32 +02:00
|
|
|
"/resolution/suggestion/{suggestion}",
|
|
|
|
api_resolution.apply_suggestion,
|
|
|
|
),
|
|
|
|
web.delete(
|
|
|
|
"/resolution/suggestion/{suggestion}",
|
2020-10-14 17:14:25 +02:00
|
|
|
api_resolution.dismiss_suggestion,
|
|
|
|
),
|
2020-10-16 12:22:32 +02:00
|
|
|
web.delete(
|
|
|
|
"/resolution/issue/{issue}",
|
|
|
|
api_resolution.dismiss_issue,
|
|
|
|
),
|
2021-02-25 14:05:27 +01:00
|
|
|
web.post("/resolution/healthcheck", api_resolution.healthcheck),
|
2020-10-14 17:14:25 +02:00
|
|
|
]
|
|
|
|
)
|
2020-10-13 12:54:17 +02:00
|
|
|
|
2019-03-27 17:20:05 +01:00
|
|
|
def _register_auth(self) -> None:
|
2018-10-12 12:21:48 +02:00
|
|
|
"""Register auth functions."""
|
|
|
|
api_auth = APIAuth()
|
|
|
|
api_auth.coresys = self.coresys
|
|
|
|
|
2020-01-15 18:16:19 +01:00
|
|
|
self.webapp.add_routes(
|
2020-10-19 16:38:28 +02:00
|
|
|
[
|
2021-01-07 21:02:36 +01:00
|
|
|
web.get("/auth", api_auth.auth),
|
2020-10-19 16:38:28 +02:00
|
|
|
web.post("/auth", api_auth.auth),
|
|
|
|
web.post("/auth/reset", api_auth.reset),
|
|
|
|
web.delete("/auth/cache", api_auth.cache),
|
|
|
|
]
|
2020-01-15 18:16:19 +01:00
|
|
|
)
|
2018-10-12 12:21:48 +02:00
|
|
|
|
2019-03-27 17:20:05 +01:00
|
|
|
def _register_supervisor(self) -> None:
|
2018-09-18 23:47:47 +02:00
|
|
|
"""Register Supervisor functions."""
|
2018-01-02 21:21:29 +01:00
|
|
|
api_supervisor = APISupervisor()
|
|
|
|
api_supervisor.coresys = self.coresys
|
2017-03-30 16:54:13 +02:00
|
|
|
|
2019-05-27 12:35:06 +02:00
|
|
|
self.webapp.add_routes(
|
|
|
|
[
|
|
|
|
web.get("/supervisor/ping", api_supervisor.ping),
|
|
|
|
web.get("/supervisor/info", api_supervisor.info),
|
|
|
|
web.get("/supervisor/stats", api_supervisor.stats),
|
|
|
|
web.get("/supervisor/logs", api_supervisor.logs),
|
|
|
|
web.post("/supervisor/update", api_supervisor.update),
|
|
|
|
web.post("/supervisor/reload", api_supervisor.reload),
|
2020-11-21 12:48:16 +01:00
|
|
|
web.post("/supervisor/restart", api_supervisor.restart),
|
2019-05-27 12:35:06 +02:00
|
|
|
web.post("/supervisor/options", api_supervisor.options),
|
2019-08-07 17:26:32 +02:00
|
|
|
web.post("/supervisor/repair", api_supervisor.repair),
|
2019-05-27 12:35:06 +02:00
|
|
|
]
|
|
|
|
)
|
2017-03-30 16:54:13 +02:00
|
|
|
|
2019-03-27 17:20:05 +01:00
|
|
|
def _register_homeassistant(self) -> None:
|
2018-09-18 23:47:47 +02:00
|
|
|
"""Register Home Assistant functions."""
|
2018-01-02 21:21:29 +01:00
|
|
|
api_hass = APIHomeAssistant()
|
|
|
|
api_hass.coresys = self.coresys
|
2017-03-30 16:01:52 +02:00
|
|
|
|
2019-05-27 12:35:06 +02:00
|
|
|
self.webapp.add_routes(
|
|
|
|
[
|
2020-02-05 10:57:57 +01:00
|
|
|
web.get("/core/info", api_hass.info),
|
|
|
|
web.get("/core/logs", api_hass.logs),
|
|
|
|
web.get("/core/stats", api_hass.stats),
|
|
|
|
web.post("/core/options", api_hass.options),
|
|
|
|
web.post("/core/update", api_hass.update),
|
|
|
|
web.post("/core/restart", api_hass.restart),
|
|
|
|
web.post("/core/stop", api_hass.stop),
|
|
|
|
web.post("/core/start", api_hass.start),
|
|
|
|
web.post("/core/check", api_hass.check),
|
|
|
|
web.post("/core/rebuild", api_hass.rebuild),
|
2020-02-21 17:55:41 +01:00
|
|
|
# Remove with old Supervisor fallback
|
2019-05-27 12:35:06 +02:00
|
|
|
web.get("/homeassistant/info", api_hass.info),
|
|
|
|
web.get("/homeassistant/logs", api_hass.logs),
|
|
|
|
web.get("/homeassistant/stats", api_hass.stats),
|
|
|
|
web.post("/homeassistant/options", api_hass.options),
|
|
|
|
web.post("/homeassistant/update", api_hass.update),
|
|
|
|
web.post("/homeassistant/restart", api_hass.restart),
|
|
|
|
web.post("/homeassistant/stop", api_hass.stop),
|
|
|
|
web.post("/homeassistant/start", api_hass.start),
|
|
|
|
web.post("/homeassistant/check", api_hass.check),
|
|
|
|
web.post("/homeassistant/rebuild", api_hass.rebuild),
|
|
|
|
]
|
|
|
|
)
|
2017-12-26 00:51:07 +01:00
|
|
|
|
2019-03-27 17:20:05 +01:00
|
|
|
def _register_proxy(self) -> None:
|
2018-09-18 23:47:47 +02:00
|
|
|
"""Register Home Assistant API Proxy."""
|
2018-01-02 21:21:29 +01:00
|
|
|
api_proxy = APIProxy()
|
|
|
|
api_proxy.coresys = self.coresys
|
2017-12-26 00:51:07 +01:00
|
|
|
|
2019-05-27 12:35:06 +02:00
|
|
|
self.webapp.add_routes(
|
|
|
|
[
|
2020-02-05 10:57:57 +01:00
|
|
|
web.get("/core/api/websocket", api_proxy.websocket),
|
|
|
|
web.get("/core/websocket", api_proxy.websocket),
|
|
|
|
web.get("/core/api/stream", api_proxy.stream),
|
|
|
|
web.post("/core/api/{path:.+}", api_proxy.api),
|
|
|
|
web.get("/core/api/{path:.+}", api_proxy.api),
|
|
|
|
web.get("/core/api/", api_proxy.api),
|
2020-02-21 17:55:41 +01:00
|
|
|
# Remove with old Supervisor fallback
|
2019-05-27 12:35:06 +02:00
|
|
|
web.get("/homeassistant/api/websocket", api_proxy.websocket),
|
|
|
|
web.get("/homeassistant/websocket", api_proxy.websocket),
|
|
|
|
web.get("/homeassistant/api/stream", api_proxy.stream),
|
|
|
|
web.post("/homeassistant/api/{path:.+}", api_proxy.api),
|
|
|
|
web.get("/homeassistant/api/{path:.+}", api_proxy.api),
|
|
|
|
web.get("/homeassistant/api/", api_proxy.api),
|
|
|
|
]
|
|
|
|
)
|
2017-03-30 16:01:52 +02:00
|
|
|
|
2019-03-27 17:20:05 +01:00
|
|
|
def _register_addons(self) -> None:
|
2018-09-18 23:47:47 +02:00
|
|
|
"""Register Add-on functions."""
|
2018-01-02 21:21:29 +01:00
|
|
|
api_addons = APIAddons()
|
|
|
|
api_addons.coresys = self.coresys
|
2017-04-12 00:06:17 +02:00
|
|
|
|
2019-05-27 12:35:06 +02:00
|
|
|
self.webapp.add_routes(
|
|
|
|
[
|
|
|
|
web.get("/addons", api_addons.list),
|
|
|
|
web.post("/addons/reload", api_addons.reload),
|
|
|
|
web.get("/addons/{addon}/info", api_addons.info),
|
|
|
|
web.post("/addons/{addon}/uninstall", api_addons.uninstall),
|
|
|
|
web.post("/addons/{addon}/start", api_addons.start),
|
|
|
|
web.post("/addons/{addon}/stop", api_addons.stop),
|
|
|
|
web.post("/addons/{addon}/restart", api_addons.restart),
|
|
|
|
web.post("/addons/{addon}/options", api_addons.options),
|
2020-08-30 17:58:13 +02:00
|
|
|
web.post(
|
|
|
|
"/addons/{addon}/options/validate", api_addons.options_validate
|
|
|
|
),
|
2021-02-04 16:32:48 +01:00
|
|
|
web.get("/addons/{addon}/options/config", api_addons.options_config),
|
2019-05-27 12:35:06 +02:00
|
|
|
web.post("/addons/{addon}/rebuild", api_addons.rebuild),
|
|
|
|
web.get("/addons/{addon}/logs", api_addons.logs),
|
|
|
|
web.get("/addons/{addon}/icon", api_addons.icon),
|
|
|
|
web.get("/addons/{addon}/logo", api_addons.logo),
|
|
|
|
web.get("/addons/{addon}/changelog", api_addons.changelog),
|
2020-01-20 10:01:22 +01:00
|
|
|
web.get("/addons/{addon}/documentation", api_addons.documentation),
|
2019-05-27 12:35:06 +02:00
|
|
|
web.post("/addons/{addon}/stdin", api_addons.stdin),
|
|
|
|
web.post("/addons/{addon}/security", api_addons.security),
|
|
|
|
web.get("/addons/{addon}/stats", api_addons.stats),
|
|
|
|
]
|
|
|
|
)
|
2017-04-12 00:06:17 +02:00
|
|
|
|
2019-04-05 12:13:44 +02:00
|
|
|
def _register_ingress(self) -> None:
|
|
|
|
"""Register Ingress functions."""
|
|
|
|
api_ingress = APIIngress()
|
|
|
|
api_ingress.coresys = self.coresys
|
|
|
|
|
2019-05-27 12:35:06 +02:00
|
|
|
self.webapp.add_routes(
|
|
|
|
[
|
|
|
|
web.post("/ingress/session", api_ingress.create_session),
|
2020-11-06 11:52:11 +01:00
|
|
|
web.post("/ingress/validate_session", api_ingress.validate_session),
|
2019-05-27 12:35:06 +02:00
|
|
|
web.get("/ingress/panels", api_ingress.panels),
|
|
|
|
web.view("/ingress/{token}/{path:.*}", api_ingress.handler),
|
|
|
|
]
|
|
|
|
)
|
2019-04-05 12:13:44 +02:00
|
|
|
|
2021-07-27 10:06:09 +02:00
|
|
|
def _register_backups(self) -> None:
|
|
|
|
"""Register backups functions."""
|
|
|
|
api_backups = APIBackups()
|
|
|
|
api_backups.coresys = self.coresys
|
2017-07-05 18:16:14 +02:00
|
|
|
|
2019-05-27 12:35:06 +02:00
|
|
|
self.webapp.add_routes(
|
|
|
|
[
|
2021-07-27 10:06:09 +02:00
|
|
|
web.get("/snapshots", api_backups.list),
|
|
|
|
web.post("/snapshots/reload", api_backups.reload),
|
|
|
|
web.post("/snapshots/new/full", api_backups.backup_full),
|
|
|
|
web.post("/snapshots/new/partial", api_backups.backup_partial),
|
|
|
|
web.post("/snapshots/new/upload", api_backups.upload),
|
|
|
|
web.get("/snapshots/{slug}/info", api_backups.info),
|
|
|
|
web.delete("/snapshots/{slug}", api_backups.remove),
|
|
|
|
web.post("/snapshots/{slug}/restore/full", api_backups.restore_full),
|
2019-05-27 12:35:06 +02:00
|
|
|
web.post(
|
2021-07-27 10:06:09 +02:00
|
|
|
"/snapshots/{slug}/restore/partial",
|
|
|
|
api_backups.restore_partial,
|
2019-05-27 12:35:06 +02:00
|
|
|
),
|
2021-07-27 10:06:09 +02:00
|
|
|
web.get("/snapshots/{slug}/download", api_backups.download),
|
|
|
|
web.post("/snapshots/{slug}/remove", api_backups.remove),
|
|
|
|
# June 2021: /snapshots was renamed to /backups
|
|
|
|
web.get("/backups", api_backups.list),
|
|
|
|
web.post("/backups/reload", api_backups.reload),
|
|
|
|
web.post("/backups/new/full", api_backups.backup_full),
|
|
|
|
web.post("/backups/new/partial", api_backups.backup_partial),
|
|
|
|
web.post("/backups/new/upload", api_backups.upload),
|
|
|
|
web.get("/backups/{slug}/info", api_backups.info),
|
|
|
|
web.delete("/backups/{slug}", api_backups.remove),
|
|
|
|
web.post("/backups/{slug}/restore/full", api_backups.restore_full),
|
2019-05-27 12:35:06 +02:00
|
|
|
web.post(
|
2021-07-27 10:06:09 +02:00
|
|
|
"/backups/{slug}/restore/partial",
|
|
|
|
api_backups.restore_partial,
|
2019-05-27 12:35:06 +02:00
|
|
|
),
|
2021-07-27 10:06:09 +02:00
|
|
|
web.get("/backups/{slug}/download", api_backups.download),
|
2019-05-27 12:35:06 +02:00
|
|
|
]
|
|
|
|
)
|
2017-07-05 18:16:14 +02:00
|
|
|
|
2019-03-27 17:20:05 +01:00
|
|
|
def _register_services(self) -> None:
|
2018-09-18 23:47:47 +02:00
|
|
|
"""Register services functions."""
|
2018-02-08 17:19:47 +01:00
|
|
|
api_services = APIServices()
|
|
|
|
api_services.coresys = self.coresys
|
|
|
|
|
2019-05-27 12:35:06 +02:00
|
|
|
self.webapp.add_routes(
|
|
|
|
[
|
|
|
|
web.get("/services", api_services.list),
|
|
|
|
web.get("/services/{service}", api_services.get_service),
|
|
|
|
web.post("/services/{service}", api_services.set_service),
|
|
|
|
web.delete("/services/{service}", api_services.del_service),
|
|
|
|
]
|
|
|
|
)
|
2018-02-08 17:19:47 +01:00
|
|
|
|
2019-03-27 17:20:05 +01:00
|
|
|
def _register_discovery(self) -> None:
|
2018-09-18 23:47:47 +02:00
|
|
|
"""Register discovery functions."""
|
2018-02-08 17:19:47 +01:00
|
|
|
api_discovery = APIDiscovery()
|
|
|
|
api_discovery.coresys = self.coresys
|
|
|
|
|
2019-05-27 12:35:06 +02:00
|
|
|
self.webapp.add_routes(
|
|
|
|
[
|
|
|
|
web.get("/discovery", api_discovery.list),
|
|
|
|
web.get("/discovery/{uuid}", api_discovery.get_discovery),
|
|
|
|
web.delete("/discovery/{uuid}", api_discovery.del_discovery),
|
|
|
|
web.post("/discovery", api_discovery.set_discovery),
|
2019-08-13 14:20:42 +02:00
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
def _register_dns(self) -> None:
|
|
|
|
"""Register DNS functions."""
|
|
|
|
api_dns = APICoreDNS()
|
|
|
|
api_dns.coresys = self.coresys
|
|
|
|
|
|
|
|
self.webapp.add_routes(
|
|
|
|
[
|
|
|
|
web.get("/dns/info", api_dns.info),
|
|
|
|
web.get("/dns/stats", api_dns.stats),
|
|
|
|
web.get("/dns/logs", api_dns.logs),
|
|
|
|
web.post("/dns/update", api_dns.update),
|
|
|
|
web.post("/dns/options", api_dns.options),
|
2019-08-18 11:46:23 +02:00
|
|
|
web.post("/dns/restart", api_dns.restart),
|
2020-01-09 22:27:39 +01:00
|
|
|
web.post("/dns/reset", api_dns.reset),
|
2020-02-25 18:37:06 +01:00
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
def _register_audio(self) -> None:
|
|
|
|
"""Register Audio functions."""
|
|
|
|
api_audio = APIAudio()
|
|
|
|
api_audio.coresys = self.coresys
|
|
|
|
|
|
|
|
self.webapp.add_routes(
|
|
|
|
[
|
|
|
|
web.get("/audio/info", api_audio.info),
|
|
|
|
web.get("/audio/stats", api_audio.stats),
|
|
|
|
web.get("/audio/logs", api_audio.logs),
|
|
|
|
web.post("/audio/update", api_audio.update),
|
|
|
|
web.post("/audio/restart", api_audio.restart),
|
2020-02-26 11:48:11 +01:00
|
|
|
web.post("/audio/reload", api_audio.reload),
|
2020-02-27 16:25:04 +01:00
|
|
|
web.post("/audio/profile", api_audio.set_profile),
|
2020-02-28 17:52:12 +01:00
|
|
|
web.post("/audio/volume/{source}/application", api_audio.set_volume),
|
2020-02-26 11:48:11 +01:00
|
|
|
web.post("/audio/volume/{source}", api_audio.set_volume),
|
2020-02-28 17:52:12 +01:00
|
|
|
web.post("/audio/mute/{source}/application", api_audio.set_mute),
|
|
|
|
web.post("/audio/mute/{source}", api_audio.set_mute),
|
2020-02-26 11:48:11 +01:00
|
|
|
web.post("/audio/default/{source}", api_audio.set_default),
|
2019-05-27 12:35:06 +02:00
|
|
|
]
|
|
|
|
)
|
2018-02-08 17:19:47 +01:00
|
|
|
|
2021-02-25 16:15:51 +01:00
|
|
|
def _register_store(self) -> None:
|
|
|
|
"""Register store endpoints."""
|
|
|
|
api_store = APIStore()
|
|
|
|
api_store.coresys = self.coresys
|
|
|
|
|
|
|
|
self.webapp.add_routes(
|
|
|
|
[
|
|
|
|
web.get("/store", api_store.store_info),
|
|
|
|
web.get("/store/addons", api_store.addons_list),
|
|
|
|
web.get("/store/addons/{addon}", api_store.addons_addon_info),
|
|
|
|
web.get("/store/addons/{addon}/{version}", api_store.addons_addon_info),
|
|
|
|
web.post(
|
|
|
|
"/store/addons/{addon}/install", api_store.addons_addon_install
|
|
|
|
),
|
|
|
|
web.post(
|
|
|
|
"/store/addons/{addon}/install/{version}",
|
|
|
|
api_store.addons_addon_install,
|
|
|
|
),
|
|
|
|
web.post("/store/addons/{addon}/update", api_store.addons_addon_update),
|
|
|
|
web.post(
|
|
|
|
"/store/addons/{addon}/update/{version}",
|
|
|
|
api_store.addons_addon_update,
|
|
|
|
),
|
|
|
|
web.post("/store/reload", api_store.reload),
|
|
|
|
web.get("/store/repositories", api_store.repositories_list),
|
|
|
|
web.get(
|
|
|
|
"/store/repositories/{repository}",
|
|
|
|
api_store.repositories_repository_info,
|
|
|
|
),
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
# Reroute from legacy
|
|
|
|
self.webapp.add_routes(
|
|
|
|
[
|
|
|
|
web.post("/addons/{addon}/install", api_store.addons_addon_install),
|
|
|
|
web.post("/addons/{addon}/update", api_store.addons_addon_update),
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
2019-03-27 17:20:05 +01:00
|
|
|
def _register_panel(self) -> None:
|
2018-09-18 23:47:47 +02:00
|
|
|
"""Register panel for Home Assistant."""
|
2018-05-28 23:16:03 +02:00
|
|
|
panel_dir = Path(__file__).parent.joinpath("panel")
|
2019-05-27 12:35:06 +02:00
|
|
|
self.webapp.add_routes([web.static("/app", panel_dir)])
|
2017-05-13 17:41:46 +02:00
|
|
|
|
2020-10-05 12:19:25 +02:00
|
|
|
def _register_docker(self) -> None:
|
|
|
|
"""Register docker configuration functions."""
|
|
|
|
api_docker = APIDocker()
|
|
|
|
api_docker.coresys = self.coresys
|
|
|
|
|
|
|
|
self.webapp.add_routes(
|
|
|
|
[
|
2020-10-06 11:26:56 +02:00
|
|
|
web.get("/docker/info", api_docker.info),
|
2020-10-05 12:19:25 +02:00
|
|
|
web.get("/docker/registries", api_docker.registries),
|
|
|
|
web.post("/docker/registries", api_docker.create_registry),
|
2020-10-06 16:02:22 +02:00
|
|
|
web.delete("/docker/registries/{hostname}", api_docker.remove_registry),
|
2020-10-05 12:19:25 +02:00
|
|
|
]
|
|
|
|
)
|
|
|
|
|
2019-03-27 17:20:05 +01:00
|
|
|
async def start(self) -> None:
|
2018-09-18 23:47:47 +02:00
|
|
|
"""Run RESTful API webserver."""
|
2018-06-20 12:17:33 +02:00
|
|
|
await self._runner.setup()
|
2018-07-25 01:46:54 +02:00
|
|
|
self._site = web.TCPSite(
|
2019-05-27 12:35:06 +02:00
|
|
|
self._runner, host="0.0.0.0", port=80, shutdown_timeout=5
|
|
|
|
)
|
2017-03-30 16:01:52 +02:00
|
|
|
|
|
|
|
try:
|
2018-06-20 12:17:33 +02:00
|
|
|
await self._site.start()
|
2017-03-30 16:01:52 +02:00
|
|
|
except OSError as err:
|
2020-05-21 12:00:52 +02:00
|
|
|
_LOGGER.critical("Failed to create HTTP server at 0.0.0.0:80 -> %s", err)
|
2018-07-25 01:46:54 +02:00
|
|
|
else:
|
2020-10-15 14:50:43 +02:00
|
|
|
_LOGGER.info("Starting API on %s", self.sys_docker.network.supervisor)
|
2017-03-30 16:01:52 +02:00
|
|
|
|
2019-03-27 17:20:05 +01:00
|
|
|
async def stop(self) -> None:
|
2018-09-18 23:47:47 +02:00
|
|
|
"""Stop RESTful API webserver."""
|
2018-06-30 22:06:18 +02:00
|
|
|
if not self._site:
|
|
|
|
return
|
|
|
|
|
|
|
|
# Shutdown running API
|
2018-06-20 12:17:33 +02:00
|
|
|
await self._site.stop()
|
|
|
|
await self._runner.cleanup()
|
2018-07-25 01:46:54 +02:00
|
|
|
|
2020-10-15 14:50:43 +02:00
|
|
|
_LOGGER.info("Stopping API on %s", self.sys_docker.network.supervisor)
|