def file_info(filename: str, nb_secrets: int) -> str: """ Return the formatted file info (number of secrets + filename). """ return "\n{} {} {} been found in file {}\n".format( ICON_BY_OS.get(os.name, ICON_BY_OS["default"]), format_text(str(nb_secrets), STYLE["nb_secrets"]), pluralize("incident has", nb_secrets, "incidents have"), format_text(filename, STYLE["filename"]), )
def policy_break_header(issue_n: int, policy_breaks: List[PolicyBreak], ignore_sha: str) -> str: return "\n{} Incident {}({}): {} (Ignore with SHA: {}) ({} {})\n".format( format_text(">>>", STYLE["detector_line_start"]), issue_n, format_text(policy_breaks[0].policy, STYLE["detector"]), format_text(policy_breaks[0].break_type, STYLE["detector"]), format_text(ignore_sha, STYLE["ignore_sha"]), len(policy_breaks), pluralize("occurrence", len(policy_breaks), "occurrences"), )
def optional_header(self) -> str: """ Return the formatted patch. """ return ( format_text(f"\ncommit {self.sha}\n", STYLE["commit_info"]) + f"Author: {self.info.author} <{self.info.email}>\n" + f"Date: {self.info.date}\n" )
def format_detector(match_type: str, index_start: int, index_end: int) -> str: """ Return detector object to add in detector_line. """ detector_size = len(match_type) secret_size = index_end - index_start display = "" if secret_size < MAX_SECRET_SIZE: before = "_" * max(1, int(((secret_size - detector_size) - 1) / 2)) after = "_" * max(1, (secret_size - len(before) - detector_size) - 2) display = "|{}{}{}|".format(before, match_type, after) return " " * index_start + format_text(display, STYLE["detector"]) + "\n"
def scan_commit_range( client: GGClient, cache: Cache, commit_list: List[str], output_handler: OutputHandler, verbose: bool, filter_set: Set[str], matches_ignore: Iterable[str], all_policies: bool, scan_id: str, ) -> int: # pragma: no cover """ Scan every commit in a range. :param client: Public Scanning API client :param commit_range: Range of commits to scan (A...B) :param verbose: Display successfull scan's message """ return_code = 0 with concurrent.futures.ThreadPoolExecutor( max_workers=min(CPU_COUNT, 4)) as executor: future_to_process = [ executor.submit( scan_commit, Commit(sha, filter_set), client, cache, verbose, matches_ignore, all_policies, ) for sha in commit_list ] scans: List[ScanCollection] = [] with click.progressbar( length=len(future_to_process), label=format_text("Scanning Commits", STYLE["progress"]), ) as bar: processed = 0 for future in concurrent.futures.as_completed(future_to_process): scans.append(future.result()) processed += 1 bar.update(processed) return_code = output_handler.process_scan( ScanCollection(id=scan_id, type="commit-range", scans=scans))[1] return return_code
def format_line_count_break(padding: int) -> str: """Return the line count break.""" return format_text(" " * max(0, padding - len("...")) + "...\n", STYLE["detector_line_start"])
def no_leak_message() -> str: """ Build a message if no secret is found. """ return format_text("No secrets have been found\n", STYLE["no_secret"])
def display_detector(detector: str, offset: int) -> str: """ Return the formatted detector line. """ return " " * offset + format_text(detector, STYLE["detector"])
def display_match_value(match_value: str) -> str: """ Return the formatted match value. """ return format_text(match_value, STYLE["secret"])
def display_patch(patch: str) -> str: """ Return the formatted patch. """ return format_text(patch, STYLE["patch"])
def display_detector(detector_line: List, offset: int) -> str: """ Return the formatted detector line. """ return format_text(format_detector_line(detector_line, offset), STYLE["detector"])