Coverage for csaf/__init__.py: 100.00%

34 statements  

« prev     ^ index     » next       coverage.py v7.6.9, created at 2024-12-18 20:12:48 +00:00

1"""Common Security Advisory Framework (CSAF) Verification and Validation.""" 

2 

3import logging 

4import os 

5import pathlib 

6from typing import no_type_check 

7 

8APP_BLURB = ( 

9 'Common Security Advisory Framework (CSAF) Verification, Validation, and Application Programming Interface (API).' 

10) 

11 

12APP_ALIAS = str(pathlib.Path(__file__).parent.name) 

13APP_ENV = APP_ALIAS.upper() 

14APP_NAME = locals()['__doc__'] 

15DEBUG = bool(os.getenv(f'{APP_ENV}_DEBUG', '')) 

16VERBOSE = bool(os.getenv(f'{APP_ENV}_VERBOSE', '')) 

17STRICT = bool(os.getenv(f'{APP_ENV}_STRICT', '')) 

18ENCODING = 'utf-8' 

19ENCODING_ERRORS_POLICY = 'ignore' 

20DEFAULT_CONFIG_NAME = f'.{APP_ALIAS}.json' 

21 

22FAKE_SECRET = '*' * 13 

23 

24BAIL_OUT = bool(os.getenv(f'{APP_ENV}_BAIL_OUT', '')) 

25DRY_RUN = bool(os.getenv(f'{APP_ENV}_DRY_RUN', '')) 

26QUIET = bool(os.getenv(f'{APP_ENV}_QUIET', '')) 

27 

28log = logging.getLogger() # Temporary refactoring: module level logger 

29LOG_FOLDER = pathlib.Path('logs') 

30LOG_FILE = f'{APP_ALIAS}.log' 

31LOG_PATH = pathlib.Path(LOG_FOLDER, LOG_FILE) if LOG_FOLDER.is_dir() else pathlib.Path(LOG_FILE) 

32LOG_LEVEL = logging.INFO 

33 

34 

35@no_type_check 

36def init_logger(name=None, level=None): 

37 """Initialize module level logger""" 

38 global log # pylint: disable=global-statement 

39 

40 log_format = { 

41 'format': '%(asctime)s.%(msecs)03d %(levelname)s [%(name)s]: %(message)s', 

42 'datefmt': '%Y-%m-%dT%H:%M:%S', 

43 # 'filename': LOG_PATH, 

44 'level': LOG_LEVEL if level is None else level, 

45 } 

46 logging.basicConfig(**log_format) 

47 log = logging.getLogger(APP_ENV if name is None else name) 

48 log.propagate = True 

49 

50 

51init_logger(name=APP_ENV, level=logging.DEBUG if DEBUG else None) 

52 

53from csaf.csaf import is_valid # noqa 

54 

55# [[[fill git_describe()]]] 

56__version__ = '2024.12.18+parent.g6fed6304' 

57# [[[end]]] (checksum: 6f538b87247d65ef5c983425576897a6) 

58__version_info__ = tuple( 

59 e if '-' not in e else e.split('-')[0] for part in __version__.split('+') for e in part.split('.') if e != 'parent' 

60) 

61__all__ = ['is_valid', 'log']