Created
June 30, 2020 17:59
-
-
Save chadtsigler/7e5f8787cd55f80ef39bcdad4a63d33a to your computer and use it in GitHub Desktop.
Parameterized Virtru Python Application.
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
# Requires the Virtru Python SDK | |
# https://pypi.org/project/virtru-sdk/ | |
# https://developer.virtru.com/docs/python-encryption | |
import argparse | |
from virtru_sdk import Client, Policy, EncryptFileParams | |
def main(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument("-o", "--owner", help="AppId Owner (user@domain.com)", required=True) | |
parser.add_argument("-p", "--appid", help="AppId (1522710c-833f-4a69-8a26-0bbb00b1345c)", required=True) | |
parser.add_argument("-a", "--action", help="Action", choices=["encrypt", "decrypt"], required=True) | |
parser.add_argument("-s", "--source", help="Source File (Full path or reference path)", required=True) | |
parser.add_argument("-t", "--target", help="Target File (Full path or reference path)", required=True) | |
parser.add_argument("-u", "--users", help="Additional users added to the policy ('user1@example.com," | |
"user2@domain.com')") | |
args = parser.parse_args() | |
if args.action == "encrypt": | |
if args.users: | |
users_trim = args.users.replace(" ", "") | |
users = users_trim.split(",") | |
else: | |
users = args.users | |
encrypt(args.source, args.target, args.owner, users, args.appid) | |
else: | |
decrypt(args.source, args.target, args.owner, args.appid) | |
def encrypt(source, target, owner, users, appid): | |
client = Client(owner=owner, app_id=appid) | |
policy = Policy() | |
if len(users) > 0: | |
policy.share_with_users(users) | |
param = EncryptFileParams(in_file_path=source, | |
out_file_path=target) | |
param.set_policy(policy) | |
client.encrypt_file(encrypt_file_params=param) | |
def decrypt(source, target, owner, appid): | |
client = Client(owner=owner, app_id=appid) | |
client.decrypt_file(in_file_path=source, | |
out_file_path=target) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment