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
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Noah Lavine committed Aug 30, 2017
1 parent 9b5253d commit 4919c83
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
10 changes: 9 additions & 1 deletion rho/factdecryptcommand.py
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("--decrypted-path", 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
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("--encrypted-path", dest="encrypted_path",
metavar="ENCRYPTEDPATH",
help=_("Destination 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
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("--redacted-path", dest="redacted_path",
metavar="REDACTEDPATH",
help=_("Path to write the redacted report to"))

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 4919c83

Please sign in to comment.