Password files in same configuration dir in effect #2143

pull/2160/head
nicolargo 2022-10-16 10:32:35 +02:00
parent 5947e9da36
commit 0302cdcd57
2 changed files with 16 additions and 3 deletions

View File

@ -432,13 +432,16 @@ disable=False
#server_4_port=61237
[passwords]
# Define the passwords list
# Define the passwords list related to the [serverlist] section
# Syntax: host=password
# Where: host is the hostname
# password is the clear password
# Additionally (and optionally) a default password could be defined
#localhost=abc
#default=defaultpassword
#
# Define the path of the local '.pwd' file (default is system one)
#local_password_path=~/.config/glances
##############################################################################
# Exports

View File

@ -26,12 +26,22 @@ class GlancesPassword(object):
"""This class contains all the methods relating to password."""
def __init__(self, username='glances'):
def __init__(self, username='glances', config=None):
self.username = username
self.password_dir = user_config_dir()
self.config = config
self.password_dir = self.local_password_path()
self.password_filename = self.username + '.pwd'
self.password_file = os.path.join(self.password_dir, self.password_filename)
def local_password_path(self):
"""Return the local password path.
Related toissue: Password files in same configuration dir in effect #2143
"""
return self.config.get_value('passwords',
'local_password_path',
default=user_config_dir())
def sha256_hash(self, plain_password):
"""Return the SHA-256 of the given password."""
return hashlib.sha256(b(plain_password)).hexdigest()