示例#1
0
def run():
    args = _get_cmdline_args()
    log.setLevel(logging.ERROR - args.verbose * 10)

    if args.render_html:
        issues = []
        for src in args.source:
            log.info(f"loading '{src}'")
            issues.extend(utils.load(src))

        write(issues, file=args.output, format="html")
        return 0

    if args.config:
        config = _load_config(args.config)

    rules = utils.load(args.rules)
    issues = []

    for src in args.source:
        with TemporaryDirectory() as tmp:
            copy(src, tmp)
            if not args.config:
                config = _search_config(tmp)
            issues.extend(scan(tmp, config, rules))

    write(issues, file=args.output, format=args.format)
    return bool(issues)
示例#2
0
def test_run_scan(repo: Repo, tmpdir: str):
    expected = os.path.join(tmpdir, "repo.json")
    path, _ = repo
    args = ["", path, "-f", "json", "--output", expected]
    with patch.object(sys, "argv", args):
        cli.run()

    assert len(utils.load(expected)) == 4
示例#3
0
def _load_config(file: File = None) -> Config:
    config = Config()
    if file:
        user_config = utils.load(file)
        if user_config:
            config.update(**user_config)
        else:
            log.warning(f"empty config supplied: '{_name(file)}'")

    args = _get_cmdline_args(**config.raw)
    config.update(**args.__dict__)
    log.info(f"using config\n\n{config}")
    return config
示例#4
0
def run(config: argparse.Namespace) -> List[Issue]:
    log.setLevel(logging.ERROR - config.verbose * 10)
    rules = utils.load(config.rules)

    issues: List[Issue] = []
    source_dir = config.source[0]

    config_obj = Config()
    config_obj.update(**config.__dict__)

    with TemporaryDirectory() as tmp:
        cli.copy(source_dir, tmp)
        issues.extend(cli.scan(tmp, config_obj, rules))

    return issues
示例#5
0
def test_run_scan_with_config(repo: Repo, datadir: str, tmpdir: str):
    expected = os.path.join(tmpdir, "repo.json")
    path, _ = repo
    args = [
        "",
        path,
        "-f",
        "json",
        "--output",
        expected,
        "-c",
        os.path.join(datadir, config_json),
    ]
    with patch.object(sys, "argv", args):
        cli.run()

    assert len(utils.load(expected)) == 3
示例#6
0
def rules() -> Rules:
    return utils.load(_RULES)
示例#7
0
def repo(tempdir: str) -> Repo:
    print(check_output(["./scripts/makerepo", tempdir]).decode())
    meta = utils.load(os.path.join(tempdir, "meta.yaml"))
    return os.path.join(tempdir, "repo"), meta
示例#8
0
def test_load(datadir: str, config: Config):
    assert utils.load(os.path.join(datadir, "trufflehog.json")) == config
    assert utils.load(os.path.join(datadir, "trufflehog.yaml")) == config