示例#1
0
def main(
    ctx: click.Context,
    options: types.GlobalOptions,
    repo_path: str,
    since_commit: Optional[str],
    max_depth: int,
    branch: Optional[str],
    fetch: bool,
) -> Tuple[str, Optional[GitRepoScanner]]:
    """Scan a repository already cloned to your local system."""
    git_options = types.GitOptions(since_commit=since_commit,
                                   max_depth=max_depth,
                                   branch=branch,
                                   fetch=fetch)
    scanner = None
    try:
        scanner = GitRepoScanner(options, git_options, str(repo_path))
        scanner.scan()
    except types.GitLocalException as exc:
        util.fail(f"{repo_path} is not a valid git repository.", ctx)
    except types.GitRemoteException as exc:
        util.fail(
            f"There was an error fetching from the remote repository: {exc}",
            ctx)
    except types.TartufoException as exc:
        util.fail(str(exc), ctx)
    return (str(repo_path), scanner)
def main(
    ctx: click.Context,
    options: types.GlobalOptions,
    git_url: str,
    since_commit: Optional[str],
    max_depth: int,
    branch: Optional[str],
    work_dir: Optional[str],
) -> Tuple[str, Optional[GitRepoScanner]]:
    """Automatically clone and scan a remote git repository."""
    git_options = types.GitOptions(
        since_commit=since_commit, max_depth=max_depth, branch=branch, fetch=False
    )
    repo_path: Optional[Path] = None
    if work_dir:
        # Make sure we clone into a sub-directory of the working directory
        #   so that we don't inadvertently delete the working directory
        repo_name = urlparse(git_url).path.split("/")[-1]
        repo_path = Path(work_dir) / repo_name
        repo_path.mkdir(parents=True)
    scanner = None
    try:
        repo_path = util.clone_git_repo(git_url, repo_path)
        scanner = GitRepoScanner(options, git_options, str(repo_path))
        scanner.scan()
    except types.GitException as exc:
        util.fail(f"Error cloning remote repo: {exc}", ctx)
    except types.TartufoException as exc:
        util.fail(str(exc), ctx)
    finally:
        if repo_path and repo_path.exists():
            rmtree(str(repo_path), onerror=util.del_rw)
    return (git_url, scanner)
示例#3
0
def main(
    ctx: click.Context,
    options: types.GlobalOptions,
    repo_path: str,
    since_commit: Optional[str],
    max_depth: int,
    branch: Optional[str],
    include_submodules: bool,
) -> GitRepoScanner:
    """Scan a repository already cloned to your local system."""
    git_options = types.GitOptions(
        since_commit=since_commit,
        max_depth=max_depth,
        branch=branch,
        include_submodules=include_submodules,
    )
    scanner = None
    try:
        scanner = GitRepoScanner(options, git_options, str(repo_path))
        util.process_issues(repo_path, scanner, options)
    except types.GitLocalException:
        util.fail(f"{repo_path} is not a valid git repository.", ctx)
    except types.TartufoException as exc:
        util.fail(str(exc), ctx)
    return scanner  # type: ignore
示例#4
0
def main(
    ctx: click.Context,
    options: types.GlobalOptions,
    git_url: str,
    since_commit: Optional[str],
    max_depth: int,
    branch: Optional[str],
    work_dir: Optional[str],
    include_submodules: bool,
) -> GitRepoScanner:
    """Automatically clone and scan a remote git repository."""
    git_options = types.GitOptions(
        since_commit=since_commit,
        max_depth=max_depth,
        branch=None,
        include_submodules=include_submodules,
    )
    repo_path: Optional[Path] = None
    if work_dir:
        # Make sure we clone into a sub-directory of the working directory
        #   so that we don't inadvertently delete the working directory
        repo_name = urlparse(git_url).path.split("/")[-1]
        repo_path = Path(work_dir) / repo_name
        repo_path.mkdir(parents=True)
    scanner = None
    try:
        repo_path, origin = util.clone_git_repo(git_url, repo_path)
        if branch:
            git_options.branch = f"{origin}/{branch}"
        scanner = GitRepoScanner(options, git_options, str(repo_path))
        util.process_issues(git_url, scanner, options)
    except types.GitException as exc:
        util.fail(f"Error cloning remote repo: {exc}", ctx)
    except types.TartufoException as exc:
        util.fail(str(exc), ctx)
    finally:
        if repo_path and repo_path.exists():
            rmtree(str(repo_path), onerror=util.del_rw)
    return scanner  # type: ignore