Skip to content
This repository has been archived by the owner on Jun 29, 2022. It is now read-only.

Commit

Permalink
Add path options to fact encrypt, decrypt, and redact (#249)
Browse files Browse the repository at this point in the history
* Add path options to fact encrypt, decrypt, and redact

Let users specify the path to write the encrypted, decrypted, or
redacted file to. If not given, default to not overwriting the
original report file.

* Code comment updates.
  • Loading branch information
noahl authored and chambridge committed Aug 30, 2017
1 parent 9b5253d commit abbc095
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 4 deletions.
23 changes: 22 additions & 1 deletion doc/rho.1
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,17 @@ and
.B rho fact redact
.B --reportfile=
.I file
.B [--outputfile=
.I path
.B ]
.PP
.TP
--reportfile=file
The path and filename of the comma-separated values (CSV) file to alter.
The path and filename of the comma-separated values (CSV) file to read from.
.PP
.TP
--outputfile=path
The path and filename of the comma-separated values (CSV) file to be written.
.PP
.B
Encrypting Facts
Expand All @@ -353,11 +360,18 @@ and
.B rho fact encrypt
.B --reportfile=
.I file
.B [--outputfile=
.I path
.B ]
.PP
.TP
--reportfile=file
The path and filename of the comma-separated values (CSV) file to alter.
.PP
.TP
--outputfile=path
The path and filename of the comma-separated values (CSV) file to be written.
.PP
.B
Decrypting Facts
.PP
Expand All @@ -369,11 +383,18 @@ and
.B rho fact decrypt
.B --reportfile=
.I file
.B [--outputfile=
.I path
.B ]
.PP
.TP
--reportfile=file
The path and filename of the comma-separated values (CSV) file to alter.
.PP
.TP
--outputfile=path
The path and filename of the comma-separated values (CSV) file to be written.
.PP
.PP
.SS SCANNING
The 'scan' command is the one that actually runs discovery on the network. This command scans all of the servers within the range, and then writes the information to a CSV file.
Expand Down
10 changes: 9 additions & 1 deletion rho/factdecryptcommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ def __init__(self):
self.parser.add_option("--facts", dest="facts", metavar="FACTS",
action="callback", callback=multi_arg,
default=[], help=SUPPRESS_HELP)

self.parser.add_option("--outputfile", dest="decrypted_path",
metavar="DECRYPTEDPATH",
help=_("Location for the decrypted file"))

self.facts_to_decrypt = None

def _validate_options(self):
Expand Down Expand Up @@ -111,5 +116,8 @@ def read_and_decrypt(self, path, vault):
def _do_command(self):
vault = get_vault(prompt=PROMPT)
normalized_path = os.path.normpath(self.options.report_path)
decrypted_path = (self.options.decrypted_path or
normalized_path + '-decrypted')

keys, data = self.read_and_decrypt(normalized_path, vault)
write_csv_data(keys, data, normalized_path)
write_csv_data(keys, data, decrypted_path)
11 changes: 10 additions & 1 deletion rho/factencryptcommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ def __init__(self):
self.parser.add_option("--facts", dest="facts", metavar="FACTS",
action="callback", callback=multi_arg,
default=[], help=SUPPRESS_HELP)

self.parser.add_option("--outputfile", dest="encrypted_path",
metavar="ENCRYPTEDPATH",
help=_("Location for the encrypted file"),
default=None)

self.facts_to_encrypt = None

def _validate_options(self):
Expand Down Expand Up @@ -111,5 +117,8 @@ def read_and_encrypt(self, path, vault):
def _do_command(self):
vault = get_vault(prompt=PROMPT)
normalized_path = os.path.normpath(self.options.report_path)
encrypted_path = (self.options.encrypted_path or
normalized_path + '-encrypted')

keys, data = self.read_and_encrypt(normalized_path, vault)
write_csv_data(keys, data, normalized_path)
write_csv_data(keys, data, encrypted_path)
10 changes: 9 additions & 1 deletion rho/factredactcommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ def __init__(self):
self.parser.add_option("--facts", dest="facts", metavar="FACTS",
action="callback", callback=multi_arg,
default=[], help=SUPPRESS_HELP)

self.parser.add_option("--outputfile", dest="redacted_path",
metavar="REDACTEDPATH",
help=_("Location for the redacted file"))

self.facts_to_redact = None

def _validate_options(self):
Expand Down Expand Up @@ -81,6 +86,9 @@ def _do_command(self):
data = []
keys = None
normalized_path = os.path.normpath(self.options.report_path)
redacted_path = (self.options.redacted_path or
normalized_path + '-redacted')

with open(normalized_path, 'r') as read_file:
reader = csv.DictReader(read_file, delimiter=',')
for row in reader:
Expand Down Expand Up @@ -112,4 +120,4 @@ def _do_command(self):
for row in data:
writer.writerow(row)
data_temp.close()
move(data_temp.name, normalized_path)
move(data_temp.name, redacted_path)

0 comments on commit abbc095

Please sign in to comment.