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

1from collections.abc import Callable 

2 

3from pydaconf.plugins.base import PluginBase 

4 

5 

6class FileContentPlugin(PluginBase): 

7 """Load file content as variable plugin. Loads file content as variable based on prefix FILE_CONTENT:///""" 

8 

9 PREFIX='FILE_CONTENT' 

10 

11 def __init__(self) -> None: 

12 self.cache: dict[str, str]= {} 

13 

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() 

19 

20 except Exception as e: 

21 raise Exception(f"Secret cannot be loaded from file '{value}'. Error", e) 

22 

23 self.cache[value] = content 

24 

25 return self.cache[value]