Created
May 5, 2016 07:16
-
-
Save maatthc/63519d5439099db7fbe962f13b8b3291 to your computer and use it in GitHub Desktop.
Helper to the SoftLayer API - Helps protectig the API Key
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
import getpass | |
from cryptography.fernet import Fernet | |
import sys | |
def get_credentials(): | |
# SoftLayer Username/ Api Key encrypted | |
encrypted_credentials = b'' | |
secret_key = getpass.getpass("Please enter your secret key: ") | |
try: | |
cipher_suite = Fernet(secret_key) | |
# Decryption | |
plain_text = cipher_suite.decrypt(encrypted_credentials) | |
except Exception as e: | |
print("Invalid secret key!!!") | |
print(str(e)) | |
sys.exit(190) | |
(username, api_key) = plain_text.decode('ascii').split(":") | |
return username, api_key |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment