def __manage_credentials(self, hostname, username, password,
remove_entry=False):
"""
This functions adds or removes credentials to/from the authentication
container.
Adding credentials requires a hostname, username and corresponding
password. Removing credentials only requires a hostname.
There are two alias functions for credentials management:
add_credentials() and remove_credentials()
:param hostname: hostname
:type hostname: str
:param username: username
:type username: str
:param password: corresponding password
:type password: str
:param remove_entry: setting True will remove an entry
:type remove_entry: bool
"""
global CREDENTIALS
hostname = self.cut_hostname(hostname)
try:
if remove_entry:
#remove entry
del self.CREDENTIALS[hostname]
else:
#add entry
self.CREDENTIALS[hostname] = {}
self.CREDENTIALS[hostname]["username"] = username
#add encrypted or plain password
if self.KEY:
crypto = Fernet(self.KEY)
self.CREDENTIALS[hostname]["password"] = "s/{0}".format(
crypto.encrypt(password.encode()))
else:
self.CREDENTIALS[hostname]["password"] = password
except InvalidToken:
raise ContainerException("Invalid password specified!")
except KeyError:
pass
#aliases
评论列表
文章目录