clean up some style

This commit is contained in:
Antonio J. Delgado 2024-11-12 10:31:01 +02:00
parent 1f1cd4c394
commit 18ac819707

View file

@ -327,7 +327,7 @@ class NextcloudHandler:
)[0].firstChild.data
}
except Exception:
# I guess it's folder, because it has no content_type
# (markuman) I guess it's folder, because it has no content_type
return {
'last_modified': dom.getElementsByTagName(
'd:getlastmodified'
@ -471,6 +471,7 @@ class NextcloudHandler:
"error": error
}
)
return False
def request_passwords_session(self):
'''Request a Passwords API session'''
@ -500,6 +501,7 @@ class NextcloudHandler:
"password_hash": password_hash
}
)
return False
def close_passwords_session(self):
'''Close Passwords API session'''
@ -550,14 +552,13 @@ class NextcloudHandler:
)
if r.status_code == 201:
return r.json()
else:
self.error(
{
"action": "delete_passwords_folder",
"message": f"Nextcloud instance returned status code {r.status_code}",
"folder_name": name
}
)
self.error(
{
"action": "delete_passwords_folder",
"message": f"Nextcloud instance returned status code {r.status_code}",
"folder_name": name
}
)
else:
self.error(
{
@ -566,6 +567,7 @@ class NextcloudHandler:
"folder_name": name
}
)
return False
def exists_passwords_folder(self, name):
'''Test if a passwords folder exists'''
@ -592,14 +594,13 @@ class NextcloudHandler:
if r.status_code == 201:
return r.json()
else:
self.error(
{
"action": "create_passwords_folder",
"message": f"Nextcloud instance returned status code {r.status_code}",
"folder_name": name
}
)
self.error(
{
"action": "create_passwords_folder",
"message": f"Nextcloud instance returned status code {r.status_code}",
"folder_name": name
}
)
else:
self.warning(
{
@ -608,6 +609,7 @@ class NextcloudHandler:
"folder_name": name
}
)
return False
def get_passwords_folder(self, name):
'''Get Passwords folder'''
@ -717,6 +719,7 @@ class NextcloudHandler:
"label": post_obj['label']
}
)
return False
def delete_password(self, post_obj):
'''Delete a password'''
@ -745,6 +748,7 @@ class NextcloudHandler:
"error": error,
}
)
return False
def update_password(self, post_obj):
@ -776,6 +780,7 @@ class NextcloudHandler:
"error": error,
}
)
return False
def is_same_key(self, key, dict1, dict2):
'''Test if two dictionaries have the same key with the same value'''
@ -790,12 +795,24 @@ class NextcloudHandler:
safer_obj2 = dict(obj2, **{ 'password': '***' })
if obj1 == obj2:
self.debug(
{"action": "notify_exact_match", "object": { "obj1": safer_obj1, "obj2": safer_obj2 } }
{
"action": "notify_exact_match",
"object": {
"obj1": safer_obj1,
"obj2": safer_obj2
}
}
)
return True
if obj1['label'] == obj2['label']:
self.debug(
{ "action": "notify_name_match", "object": { "obj1": safer_obj1, "obj2": safer_obj2 } }
{
"action": "notify_name_match",
"object": {
"obj1": safer_obj1,
"obj2": safer_obj2
}
}
)
if (
self.is_same_key('username', obj1, obj2) and
@ -917,6 +934,7 @@ class NcPasswordClient:
"object": name
}
)
return False
def create_passwords_folder(self, name):
'''Create a passwords folder'''
@ -968,7 +986,10 @@ class NcPasswordClient:
)
if answer != "Y":
self.info(
{ "action": "delete_all_passwords", "message": "Aborting after answering something different from 'Y'" }
{
"action": "delete_all_passwords",
"message": "Aborting after answering something different from 'Y'"
}
)
return False
for item in self.nc.list_passwords():
@ -981,7 +1002,8 @@ class NcPasswordClient:
}
)
self.nc.delete_password(item)
return True
def remove_duplicates(self):
'''Remove duplicate passwords'''
checked_passwords = []