Source code for credsweeper.config.config

import re
from typing import Dict, List, Optional, Set, Any

from humanfriendly import parse_size

from credsweeper.common.constants import Severity, DEFAULT_PATTERN_LEN, Confidence
from credsweeper.utils.util import Util


[docs] class Config: """Class that contain configs that can be changed by user.""" def __init__(self, config: Dict[str, Any]) -> None: self.exclude_path_pattern = re.compile(Util.get_regex_combine_or(config['exclude']['path_pattern']), flags=re.IGNORECASE) self.exclude_paths: List[str] = config["exclude"]["path"] self.exclude_containers: List[str] = config["exclude"]["containers"] self.exclude_documents: List[str] = config["exclude"]["documents"] self.exclude_extensions: List[str] = config["exclude"]["extension"] self.exclude_lines: Set[str] = set(config["exclude"].get("lines") or []) self.exclude_patterns: List[re.Pattern] = [ re.compile(pattern) for pattern in (config["exclude"].get("patterns") or []) ] self.exclude_values: Set[str] = set(config["exclude"].get("values") or []) self.source_extensions: List[str] = config["source_ext"] self.source_quote_ext: List[str] = config["source_quote_ext"] self.find_by_ext_list: List[str] = config["find_by_ext_list"] self.bruteforce_list: List[str] = config["bruteforce_list"] self.check_for_literals: bool = config["check_for_literals"] self.use_filters: bool = config["use_filters"] self.line_data_output: List[str] = config["line_data_output"] self.candidate_output: List[str] = config["candidate_output"] self.find_by_ext: bool = config["find_by_ext"] self.size_limit: Optional[int] = parse_size(config["size_limit"]) if config["size_limit"] is not None else None self.pedantic: bool = bool(config["pedantic"]) self.depth: int = int(config["depth"]) self.doc: bool = config["doc"] self.severity: Severity = Severity.get(config.get("severity")) self.confidence: Confidence = Confidence.get(config.get("confidence")) self.max_url_cred_value_length: int = int(config["max_url_cred_value_length"]) self.max_password_value_length: int = int(config["max_password_value_length"]) self.pattern_len = config.get("pattern_len", DEFAULT_PATTERN_LEN)