Ejemplo n.º 1
0
def run(args):
    src = Path(args.src)
    if not src.exists():
        debug(f"{src} does not exist")
        raise FileNotFoundError

    if src.is_file():
        files = [src.as_posix()]
    elif src.is_dir():
        files = []
    else:
        debug(f"{src} is neither a file nor a directory")
        raise TypeError

    # Configure execution
    if not args.config:
        configpath = Path(__file__).parent
        configfile = configpath.joinpath("config.yml").as_posix()
        args.config = load_config(configfile, src=args.src)

    # Include files
    for incfile in args.config["include"]["files"]:
        files += set(src.glob(incfile))

    # Exclude files
    files = list(set(files) - set(args.config["exclude"]["files"]))

    # Scan files
    whispers = WhisperSecrets(args)
    for filename in files:
        for secret in whispers.scan(filename):
            if secret:
                yield secret
Ejemplo n.º 2
0
def run(src: str, config=None, dst=None):
    source = src
    src = Path(src)
    if not src.exists():
        debug(f"{src} does not exist")
        raise FileNotFoundError

    if src.is_file():
        files = [src.as_posix()]
    elif src.is_dir():
        files = []
    else:
        debug(f"{src} is neither a file nor a directory")
        raise TypeError

    # Configure execution
    if not config:
        configpath = Path(__file__).parent
        configfile = configpath.joinpath("config.yml").as_posix()
        config = load_config(configfile, src=src)

    # Include files
    for incfile in config["include"]["files"]:
        files += set(src.glob(incfile))

    # Exclude files
    files = list(set(files) - set(config["exclude"]["files"]))

    if dst and not os.path.isdir(dst):
        os.mkdir(dst)

    # Scan files
    whispers = WhisperSecrets(config)
    for filename in files:
        # print(filename)
        try:
            for secret in whispers.scan(filename):
                if secret:
                    if dst: save_file(filename, dst)
                    yield secret
        except Exception as e:
            print(f"Error: {e}")
Ejemplo n.º 3
0
def test_is_static(key, value, expectation):
    args = parse_args([fixture_path()])
    args.config = core.load_config(CONFIG_PATH.joinpath("example.yml"))
    secrets = WhisperSecrets(args)
    assert secrets.is_static(key, value) == expectation