summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicolargo <nicolas@nicolargo.com>2022-10-16 10:32:35 +0200
committernicolargo <nicolas@nicolargo.com>2022-10-16 10:32:35 +0200
commit0302cdcd57edc631bab28312c94429aada6a874d (patch)
tree9733a508b9e1d3ebbab5189177f50093b9826154
parent5947e9da36e17f352c5f13aeccb00d877f21fb37 (diff)
Password files in same configuration dir in effect #2143
-rw-r--r--conf/glances.conf5
-rw-r--r--glances/password.py14
2 files changed, 16 insertions, 3 deletions
diff --git a/conf/glances.conf b/conf/glances.conf
index 86c2b92a..986b523a 100644
--- a/conf/glances.conf
+++ b/conf/glances.conf
@@ -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
diff --git a/glances/password.py b/glances/password.py
index e3b1a8d9..26919ca6 100644
--- a/glances/password.py
+++ b/glances/password.py
@@ -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()