Coverage for pydaconf/plugins/file_content.py: 82.35%
15 statements
« prev ^ index » next coverage.py v7.6.11, created at 2025-02-16 17:46 +0000
« prev ^ index » next coverage.py v7.6.11, created at 2025-02-16 17:46 +0000
1from collections.abc import Callable
3from pydaconf.plugins.base import PluginBase
6class FileContentPlugin(PluginBase):
7 """Load file content as variable plugin. Loads file content as variable based on prefix FILE_CONTENT:///"""
9 PREFIX='FILE_CONTENT'
11 def __init__(self) -> None:
12 self.cache: dict[str, str]= {}
14 def run(self, value: str, on_update_callback: Callable[[str], None]) -> str:
15 if value not in self.cache: 15 ↛ 25line 15 didn't jump to line 25 because the condition on line 15 was always true
16 try:
17 with open(value) as file:
18 content = file.read()
20 except Exception as e:
21 raise Exception(f"Secret cannot be loaded from file '{value}'. Error", e)
23 self.cache[value] = content
25 return self.cache[value]