from .enums import DNSRecordTypeEnum, PolicyActionEnum, PolicyFlagEnum
-from .files import AbsoluteDir, Dir, File, FilePath
+from .files import AbsoluteDir, Dir, File, FilePath, WritableFile, ReadableFile
from .generic_types import ListOrItem
from .types import (
DomainName,
"SizeUnit",
"TimeUnit",
"AbsoluteDir",
+ "ReadableFile",
+ "WritableFile",
"File",
"FilePath",
"Dir",
+from logging import debug
+from os import close
from pathlib import Path
from typing import Any, Dict, Tuple, Type, TypeVar
raise ValueError(f"path '{self._value}' does not point inside an existing directory")
if self.strict_validation and self._value.is_dir():
raise ValueError(f"path '{self._value}' points to a directory when we expected a file")
+
+
+class ReadableFile(UncheckedPath):
+ """
+ File, that is enforced to be:
+ - readable by kresd
+ """
+ def __init__(
+ self, source_value: Any, parents: Tuple["UncheckedPath", ...] = tuple(), object_path: str = "/"
+ ) -> None:
+ super().__init__(source_value, parents=parents, object_path=object_path)
+ try:
+ f = open(self._value, "r")
+ except IOError as e:
+ if e.args == (13, 'permission denied'):
+ raise ValueError(f"file'{self._value}' isn't readable")
+ raise ValueError(f"Unexpected error '{e}'")
+
+ f.close()
+
+
+class WritableFile(UncheckedPath):
+ """
+ File, that is enforced to be:
+ - writable by kresd
+ """
+ def __init__(
+ self, source_value: Any, parents: Tuple["UncheckedPath", ...] = tuple(), object_path: str = "/"
+ ) -> None:
+ print(type(self))
+ super().__init__(source_value, parents=parents, object_path=object_path)
+ try:
+ f = open(self._value, "w")
+ except IOError as e:
+ if e.args == (13, 'permission denied'):
+ raise ValueError(f"file'{self._value}' isn't readable")
+ raise ValueError(f"Unexpected error '{e}'")
+
+ f.close()
+
+
from aiohttp.web_runner import AppRunner, TCPSite, UnixSite
from typing_extensions import Literal
+from knot_resolver_manager.datamodel.types.files import ReadableFile, WritableFile
import knot_resolver_manager.utils.custom_atexit as atexit
from knot_resolver_manager import log, statistics
from knot_resolver_manager.compat import asyncio as asyncio_compat
# This function is quite long, but it describes how manager runs. So let's silence pylint
# pylint: disable=too-many-statements
+ ReadableFile(config)
start_time = time()
working_directory_on_startup = os.getcwd()
manager: Optional[KresManager] = None
logger.error(e)
return 1
+ except PermissionError as e:
+ logger.error(f"Reading of the configuration file failed: {e}")
+ # logger.error("Insufficient permissions")
+ return 1
+
except BaseException:
logger.error("Uncaught generic exception during manager inicialization...", exc_info=True)
return 1