Ansible Script 추가
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
import base64, random, string, os
|
||||
from Crypto.Cipher import AES
|
||||
from Crypto.Random import get_random_bytes
|
||||
from Crypto.Util.Padding import pad, unpad
|
||||
|
||||
try:
|
||||
encrypt_flag=True if os.sys.argv[1].lower()=='1' else False
|
||||
except Exception as err:
|
||||
encrypt_flag=False
|
||||
|
||||
def generate_password(length=8, num_uppercase=1, num_lowercase=1, num_digits=1, num_sp_char=1):
|
||||
sp_char = '!@#$'
|
||||
all_chars = string.ascii_letters + string.digits + sp_char
|
||||
|
||||
password = [
|
||||
*random.choices(string.ascii_uppercase, k=num_uppercase),
|
||||
*random.choices(string.ascii_lowercase, k=num_lowercase),
|
||||
*random.choices(string.digits, k=num_digits),
|
||||
*random.choices(sp_char, k=num_sp_char)
|
||||
]
|
||||
|
||||
remaining_length = length - (num_uppercase + num_lowercase + num_digits + num_sp_char)
|
||||
password += random.choices(all_chars, k=remaining_length)
|
||||
|
||||
random.shuffle(password)
|
||||
return ''.join(password)
|
||||
|
||||
def encrypt(plain_text, key):
|
||||
manual_iv = b'PhilinnovatorDEV'
|
||||
cipher = AES.new(key, AES.MODE_CBC, iv=manual_iv)
|
||||
ct_bytes = cipher.encrypt(pad(plain_text.encode(), 16))
|
||||
ct = base64.b64encode(ct_bytes).decode('utf-8')
|
||||
return ct
|
||||
|
||||
key = b'PhilinnovatorDEVPhilinnovatorDEV'
|
||||
plain_text = generate_password()
|
||||
|
||||
if encrypt_flag:
|
||||
encrypted_text = encrypt(plain_text, key)
|
||||
print(encrypted_text)
|
||||
else:
|
||||
print(plain_text)
|
||||
@@ -0,0 +1,11 @@
|
||||
import hvac
|
||||
|
||||
str_url = "http://10.10.43.98:31080"
|
||||
str_token = "hvs.CAESIMV6zCg-GpUP4pQgVA5f1ZXkgyJZrqOC6QDCegrpiAX9Gh4KHGh2cy5ORkpkc2ZyVUxYd09qUVFtQldRNDBjS3I"
|
||||
client = hvac.Client(url=str_url, token=str_token)
|
||||
|
||||
str_mount_point = 'kv'
|
||||
str_secret_path = 'host1'
|
||||
read_secret_result = client.secrets.kv.v1.read_secret(mount_point=str_mount_point, path=str_secret_path)
|
||||
print(read_secret_result)
|
||||
|
||||
Reference in New Issue
Block a user