Skip to content

Commit

Permalink
Add methods for use as a library
Browse files Browse the repository at this point in the history
  • Loading branch information
dinvlad committed Sep 2, 2020
1 parent b708a0f commit a787ca9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,23 @@ or even to be authenticated with Google Cloud SDK.

Python 3.7+

## Usage
## Installation

```
pip3 install find-gcp-keys

## Usage

As a command-line utility:

```
find_gcp_keys <dir_path>
```

As a library:

```
import find_gcp_keys
...
for path in find_gcp_keys.search(dir_path):
print(path)
```
5 changes: 5 additions & 0 deletions find_gcp_keys/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""
Finds and reports valid Google Service Account keys on your filesystem
"""

from find_gcp_keys.__main__ import find_key_paths, is_valid_key, search
14 changes: 10 additions & 4 deletions find_gcp_keys/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,21 @@ def is_valid_key(file_path: str):
return False


def search(dir_path: str):
""" Recursively walks `dir_path` and finds valid GCP SA keys """
for path in find_key_paths(dir_path):
if is_valid_key(path):
yield path


def main():
""" Main entrypoint """
args = parse_args()

found = False
for path in find_key_paths(args.dir_path):
if is_valid_key(path):
print(path, file=sys.stderr)
found = True
for path in search(args.dir_path):
print(path, file=sys.stderr)
found = True

if found:
sys.exit(1)
Expand Down

0 comments on commit a787ca9

Please sign in to comment.