Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit of SOPS encryption logic
- Loading branch information
A.J. Herbert
committed
Apr 27, 2018
1 parent
4ddab2e
commit a7da708
Showing
3 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import os | ||
import subprocess | ||
import sys | ||
|
||
|
||
def key_check(): | ||
if not os.getenv('SOPS_KMS_ARN'): | ||
sys.exit("You must obtain the master key and export it in the 'SOPS_KMS_ARN' environment variable") | ||
|
||
def decrypt(secret_file_dir, secret_file_name): | ||
key_check() | ||
secret_file_path = os.path.join(secret_file_dir, secret_file_name) | ||
temp_secret_file_path = os.path.join(secret_file_dir, "tmp-" + secret_file_name) | ||
os.rename(secret_file_path, temp_secret_file_path) | ||
with open(secret_file_path, "w") as decrypted_file: | ||
subprocess.call(["sops", "-d", temp_secret_file_path], stdout=decrypted_file) | ||
|
||
def decrypt_cleanup(secret_file_dir, secret_file_name): | ||
secret_file_path = os.path.join(secret_file_dir, secret_file_name) | ||
temp_secret_file_path = os.path.join(secret_file_dir, "tmp-" + secret_file_name) | ||
os.remove(secret_file_path) | ||
os.rename(temp_secret_file_path, secret_file_path) | ||
|
||
def edit_secret(secret_file_path): | ||
key_check() | ||
subprocess.call(["sops", secret_file_path]) | ||
|
||
def view_secret(secret_file_path): | ||
key_check() | ||
subprocess.call(["sops", "-d", secret_file_path]) |