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 in CHOME 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() or add_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.

override_entry(credentials) None[source]

Override matching credentials entry with the new one.

return_credentials(host) dict[source]

Returns credentials dictionary if entry found

Something like this
{
    "user": "username",
    "host": "hostname",
    "encrypted_pass": "base64 string of encrypted password",
    "pass": "plain text password"
}

Returns empty dictionary otherwise.

exception credentials.CredentialsError[source]

Bases: Exception

exception credentials.CryptoError[source]

Bases: Exception

exception credentials.MasterkeyError[source]

Bases: Exception