Skip to content

Commit f61bd09

Browse files
authored
Merge pull request #77 from brootware/dev
Dev
2 parents 2898ba5 + 1b5d613 commit f61bd09

File tree

4 files changed

+52
-13
lines changed

4 files changed

+52
-13
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ and simply didn't have the time to go back and retroactively create one.
1616

1717
### Added
1818

19-
- None at the moment.
19+
- Added in redaction support from linux piped input.
20+
- echo 'This is my ip: 127.0.0.1. My email is [email protected]. My favorite secret link is github.com' | prk
21+
- Added docker support to run the app from docker.
2022

2123
## [0.4.0] - 2022-07-27
2224

Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM python:3.9-slim
2+
3+
USER root
4+
5+
RUN python3 -m pip install --upgrade pip && \
6+
python3 -m pip install --upgrade pyredactkit && \
7+
groupadd -r nonroot && \
8+
useradd -m -r -g nonroot -d /home/nonroot -s /usr/sbin/nologin -c "Nonroot User" nonroot && \
9+
mkdir -p /home/nonroot/workdir && \
10+
chown -R nonroot:nonroot /home/nonroot
11+
12+
USER nonroot
13+
ENV HOME /home/nonroot
14+
WORKDIR /home/nonroot/workdir
15+
VOLUME ["/home/nonroot/workdir"]
16+
ENV USER nonroot
17+
ENTRYPOINT ["/usr/local/bin/prk"]

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ Redacts and Unredacts the following from your text files. 📄 ✍️
3939
Demo:
4040
![demo](./images/pyredactdemo.gif)
4141

42+
To use via docker
43+
44+
```bash
45+
docker run -v "$(pwd):/home/nonroot/workdir" brootware/pyredactkit 'This is my ip: 127.0.0.1. My email is [email protected]. My favorite secret link is github.com'
46+
```
47+
4248
Quick install
4349

4450
```bash

pyredactkit/runner.py

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@
3636
help_menu = """
3737
PyRedactKit - Redact and Un-redact any sensitive data from your text files!
3838
Example usage:\n
39-
prk 'This is my ip: 127.0.0.1. My email is [email protected]. My favorite secret link is github.com'\n
40-
prk [file/directory_with_files]\n
41-
prk redacted_file --unredact .hashshadow.json\n
42-
prk file --customfile custom.json\n
39+
prk 'This is my ip: 127.0.0.1. My email is [email protected]. My favorite secret link is github.com'
40+
prk [file/directory_with_files]
41+
prk redacted_file --unredact .hashshadow.json
42+
prk file --customfile custom.json
43+
echo 'This is my ip: 127.0.0.1. My email is [email protected]. My favorite secret link is github.com' | prk
4344
"""
4445

4546

@@ -51,12 +52,9 @@ def arg_helper() -> argparse.Namespace:
5152
parser.add_argument(
5253
"text",
5354
help="""Supply either a text chunk or file name path to redact sensitive data from command prompt.""",
54-
nargs="*"
55+
nargs="*",
56+
default=sys.stdin
5557
)
56-
if len(sys.argv) == 1:
57-
print(help_menu)
58-
parser.print_help(sys.stderr)
59-
sys.exit(1)
6058
parser.add_argument(
6159
"-u",
6260
"--unredact",
@@ -94,9 +92,8 @@ def arg_helper() -> argparse.Namespace:
9492
default='',
9593
help='File extension to filter by.'
9694
)
97-
args = parser.parse_args()
9895

99-
return args
96+
return parser
10097

10198

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

118115

119116
def execute_redact_logic() -> None:
120-
args = arg_helper()
117+
# Access main parser namespace first
118+
parser = arg_helper()
119+
# Parse the arguments from parser object
120+
args = parser.parse_args()
121+
122+
if len(sys.argv) == 1:
123+
# If there is no input argument and no piped input, print help menu and exit
124+
if sys.stdin.isatty():
125+
print(help_menu)
126+
parser.print_help(sys.stderr)
127+
sys.exit(1)
128+
129+
# This is reading in from linux piped stdin to redact. - echo 'This is my ip: 127.0.0.1.' | prk
130+
stdin = parser.parse_args().text.read().splitlines()
131+
core_redact.process_text(stdin)
132+
sys.exit(1)
121133

134+
# 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.'
122135
is_text = is_it_file(args.text[0])
123136
if not is_text:
124137
core_redact.process_text(args.text)
125138

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

128142
for file in files:

0 commit comments

Comments
 (0)