Check if password exists with different name but same properties
This commit is contained in:
parent
3a9c124707
commit
a4b6c35784
1 changed files with 16 additions and 3 deletions
|
@ -554,15 +554,18 @@ class NextcloudHandler:
|
|||
else:
|
||||
self.exit.status_code_error(r.status_code)
|
||||
|
||||
def exists_password(self, name):
|
||||
def exists_password(self, obj):
|
||||
'''Test if a password exist with the same name'''
|
||||
for password in self.list_passwords():
|
||||
if password['label'] == name:
|
||||
if self.is_same_password(obj, password):
|
||||
return True
|
||||
if password['label'] == obj['label']:
|
||||
return True
|
||||
return False
|
||||
|
||||
def create_password(self, post_obj):
|
||||
'''Create/add a password'''
|
||||
if not self.exists_password(post_obj['label']):
|
||||
if not self.exists_password(post_obj):
|
||||
r = requests.post(
|
||||
f'{self.http}://{self.host}/index.php/apps/passwords/api/1.0/password/create',
|
||||
data=post_obj,
|
||||
|
@ -612,6 +615,16 @@ class NextcloudHandler:
|
|||
else:
|
||||
self.exit.status_code_error(r.status_code)
|
||||
|
||||
def is_same_password(self, obj1, obj2):
|
||||
'''Test if two password objects are the same or similar'''
|
||||
if obj1 == obj2:
|
||||
return True
|
||||
if (obj1['username'] == obj2['username'] and
|
||||
obj1['password'] == obj2['password'] and
|
||||
obj1['url'] == obj2['url']):
|
||||
return True
|
||||
return False
|
||||
|
||||
class NcPasswordClient:
|
||||
'''Nextcloud Password Client'''
|
||||
|
||||
|
|
Loading…
Reference in a new issue