Skip to content

Instantly share code, notes, and snippets.

@maatthc
Created May 5, 2016 07:16
Show Gist options
  • Save maatthc/63519d5439099db7fbe962f13b8b3291 to your computer and use it in GitHub Desktop.
Save maatthc/63519d5439099db7fbe962f13b8b3291 to your computer and use it in GitHub Desktop.
Helper to the SoftLayer API - Helps protectig the API Key
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