Пример #1
0
def raise_exception_if_baseline_file_is_not_up_to_date(filename):
    """We want to make sure that if there are changes to the baseline
    file, they will be included in the commit. This way, we can keep
    our baselines up-to-date.

    :raises: ValueError
    """
    try:
        files_changed_but_not_staged = subprocess.check_output(
            'git diff --name-only'.split()).split()
    except subprocess.CalledProcessError:
        # Since we don't pipe stderr, we get free logging through git.
        raise ValueError

    if filename.encode() in files_changed_but_not_staged:
        CustomLog(formatter='%(message)s').getLogger()\
            .error((
                'Your baseline file ({}) is unstaged.\n'
                '`git add {}` to fix this.'
            ).format(
                filename,
                filename,
            ))

        raise ValueError
Пример #2
0
def pretty_print_diagnostics(secrets):
    """Prints a helpful error message, for better usability.

    :type secrets: SecretsCollection
    """
    log = CustomLog(formatter='%(message)s').getLogger()

    _print_warning_header(log)
    _print_secrets_found(log, secrets)
    _print_mitigation_suggestions(log)
from __future__ import absolute_import

import os
import subprocess

from detect_secrets.core.log import CustomLog

from detect_secrets_server.repos.base_tracked_repo import BaseTrackedRepo


CustomLogObj = CustomLog()


class LocalTrackedRepo(BaseTrackedRepo):

    def cron(self):
        return "%s %s" % (super(LocalTrackedRepo, self).cron(), '--local')

    @property
    def repo_location(self):
        # When we're performing git commands on a local repository, we need to reference
        # the `/.git` folder within the cloned git repo.
        return os.path.join(self.repo, '.git')

    def clone_and_pull_repo(self):
        # Assumption: If you are scanning a local git repo, then you are "actively"
        # working on it. Therefore, this module will not bear the responsibility
        # of auto-updating the repo with `git pull`.
        pass

    @classmethod
Пример #4
0
def _get_custom_log():
    return CustomLog(formatter='%(message)s').getLogger()