From 3ade049133cc135d8201b4a7c30fcea7dd4f31ce Mon Sep 17 00:00:00 2001 From: Paul Lecuq Date: Sat, 29 Aug 2020 11:40:30 +0200 Subject: [PATCH] encrypt_password script converted to python3 --- scripts/encrypt_password | 10 ---------- scripts/encrypt_password.py | 26 ++++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 10 deletions(-) delete mode 100755 scripts/encrypt_password create mode 100755 scripts/encrypt_password.py diff --git a/scripts/encrypt_password b/scripts/encrypt_password deleted file mode 100755 index 0a8cb8b..0000000 --- a/scripts/encrypt_password +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -key_id=salt - -if [[ $1 != "" ]] -then - echo -n $1 | gpg --armor --batch --homedir="/etc/salt/gpgkeys" --trust-model always --encrypt -r "${key_id}" -else - echo "Please specify a password" -fi diff --git a/scripts/encrypt_password.py b/scripts/encrypt_password.py new file mode 100755 index 0000000..ae8ba28 --- /dev/null +++ b/scripts/encrypt_password.py @@ -0,0 +1,26 @@ +#!/usr/bin/python3 + +import argparse +import gnupg + +KEYID="salt" +GPGHOME="/etc/salt/gpgkeys" + +def parse_args(): + parser = argparse.ArgumentParser(description='Encrypt password') + parser.add_argument('password', type=str, nargs=1, + help='password to encrypt') + args = parser.parse_args() + return args + +def encrypt(password=""): + gpg = gnupg.GPG(gnupghome=GPGHOME, secret_keyring=KEYID) + encrypted_password = gpg.encrypt(password, KEYID) + return encrypted_password + + +if __name__ == "__main__": + Args = parse_args() + Password = Args.password[0] + print(f"Encrypting password {Password}") + print(encrypt(Password))