credentials module
- class credentials.Credentials(credentials_file, master_key=None)[source]
Bases:
object
A class to check, retrieve, add, encrypt and decrypt credentials necessary to connect to a switch.
- credentials_file
Relative or absolute path to a credentials file that is to be used. It is passed via the command line flag
--credentials
. If no path is passed, the default credentials file credentials inCHOME
is used.- Type:
str
- file_handle
File handle used to read from and write to credentials file.
- Type:
file
- master_key
Used to encrypt and decrypt passwords. Can have a lenth of 32 characters max. Can be passed via the -m flag and can be the actual master key (discouraged) or a relative/absolute path to a file containing the master key. If not provided
__init__()
will ask for it using the python module getpass.- Type:
str
- add_entry(credentials) None [source]
Writes entry to
credentials_file
- check_credentials_file_exists() None [source]
Checks if the passed credentials file exists. Uses default credentials file in
CHOME_ABS_PATH
- check_entry_exists(host) str [source]
Returns user@host of the match, if found, an empty string otherwise.
- checks_add_entry(credentials=None) bool [source]
- Asks for
host
user
password
Asks whether to override, if entry exists. Asks three times to repeat at most, if passwords do not match. Aborts if override is denied, otherwise calls
override_entry()
oradd_entry()
- decrypt_pass(credentials) str [source]
Decode base64 string and decrypt using
master_key
- encrypt_pass(credentials) str [source]
Encrypt password with AES using
master_key
and encode it using base64.