Skip to content
Merged

Dev #77

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ and simply didn't have the time to go back and retroactively create one.

### Added

- None at the moment.
- Added in redaction support from linux piped input.
- echo 'This is my ip: 127.0.0.1. My email is brute@gmail.com. My favorite secret link is github.com' | prk
- Added docker support to run the app from docker.

## [0.4.0] - 2022-07-27

Expand Down
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM python:3.9-slim

USER root

RUN python3 -m pip install --upgrade pip && \
python3 -m pip install --upgrade pyredactkit && \
groupadd -r nonroot && \
useradd -m -r -g nonroot -d /home/nonroot -s /usr/sbin/nologin -c "Nonroot User" nonroot && \
mkdir -p /home/nonroot/workdir && \
chown -R nonroot:nonroot /home/nonroot

USER nonroot
ENV HOME /home/nonroot
WORKDIR /home/nonroot/workdir
VOLUME ["/home/nonroot/workdir"]
ENV USER nonroot
ENTRYPOINT ["/usr/local/bin/prk"]
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ Redacts and Unredacts the following from your text files. 📄 ✍️
Demo:
![demo](./images/pyredactdemo.gif)

To use via docker

```bash
docker run -v "$(pwd):/home/nonroot/workdir" brootware/pyredactkit 'This is my ip: 127.0.0.1. My email is brute@gmail.com. My favorite secret link is github.com'
```

Quick install

```bash
Expand Down
38 changes: 26 additions & 12 deletions pyredactkit/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@
help_menu = """
PyRedactKit - Redact and Un-redact any sensitive data from your text files!
Example usage:\n
prk 'This is my ip: 127.0.0.1. My email is brute@gmail.com. My favorite secret link is github.com'\n
prk [file/directory_with_files]\n
prk redacted_file --unredact .hashshadow.json\n
prk file --customfile custom.json\n
prk 'This is my ip: 127.0.0.1. My email is brute@gmail.com. My favorite secret link is github.com'
prk [file/directory_with_files]
prk redacted_file --unredact .hashshadow.json
prk file --customfile custom.json
echo 'This is my ip: 127.0.0.1. My email is brute@gmail.com. My favorite secret link is github.com' | prk
"""


Expand All @@ -51,12 +52,9 @@ def arg_helper() -> argparse.Namespace:
parser.add_argument(
"text",
help="""Supply either a text chunk or file name path to redact sensitive data from command prompt.""",
nargs="*"
nargs="*",
default=sys.stdin
)
if len(sys.argv) == 1:
print(help_menu)
parser.print_help(sys.stderr)
sys.exit(1)
parser.add_argument(
"-u",
"--unredact",
Expand Down Expand Up @@ -94,9 +92,8 @@ def arg_helper() -> argparse.Namespace:
default='',
help='File extension to filter by.'
)
args = parser.parse_args()

return args
return parser


def is_it_file(file_path: str) -> bool:
Expand All @@ -117,12 +114,29 @@ def recursive_file_search(full_path: str, extension: str, recursive: bool) -> se


def execute_redact_logic() -> None:
args = arg_helper()
# Access main parser namespace first
parser = arg_helper()
# Parse the arguments from parser object
args = parser.parse_args()

if len(sys.argv) == 1:
# If there is no input argument and no piped input, print help menu and exit
if sys.stdin.isatty():
print(help_menu)
parser.print_help(sys.stderr)
sys.exit(1)

# This is reading in from linux piped stdin to redact. - echo 'This is my ip: 127.0.0.1.' | prk
stdin = parser.parse_args().text.read().splitlines()
core_redact.process_text(stdin)
sys.exit(1)

# This is detecting if it's a text or file input and redacting argument supplied like - prk 'This is my ip: 127.0.0.1.'
is_text = is_it_file(args.text[0])
if not is_text:
core_redact.process_text(args.text)

# This is redacting all the files.
files = recursive_file_search(args.text, args.extension, args.recursive)

for file in files:
Expand Down