|
@@ -127,3 +127,89 @@ class NewNode(object):
|
|
|
"""Set the Notes."""
|
|
|
enc = CryptoEngine.get()
|
|
|
self._notes = enc.encrypt(value).strip()
|
|
|
+
|
|
|
+
|
|
|
+class Node(object):
|
|
|
+
|
|
|
+ def __init__(self, clear_text=True, **kwargs):
|
|
|
+ if clear_text:
|
|
|
+ enc = CryptoEngine.get()
|
|
|
+ self._username = enc.encrypt(kwargs.get('username')).strip()
|
|
|
+ self._password = enc.encrypt(kwargs.get('password')).strip()
|
|
|
+ self._url = enc.encrypt(kwargs.get('url')).strip()
|
|
|
+ self._notes = enc.encrypt(kwargs.get('notes')).strip()
|
|
|
+ self._tags = [enc.encrypt(t).strip() for t in kwargs.get('tags')]
|
|
|
+
|
|
|
+ @classmethod
|
|
|
+ def from_encrypted_entries(cls, username, password, url, notes, tags):
|
|
|
+ """
|
|
|
+ We use this alternatively, to create a node instance when reading
|
|
|
+ the encrypted entities from the database
|
|
|
+ """
|
|
|
+ node = Node(clear_text=False)
|
|
|
+ node._username = username.strip()
|
|
|
+ node._password = password.strip()
|
|
|
+ node._url = url.strip()
|
|
|
+ node._notes = notes.strip()
|
|
|
+ node._tags = [t.strip() for t in tags]
|
|
|
+ return node
|
|
|
+
|
|
|
+ @property
|
|
|
+ def password(self):
|
|
|
+ """Get the current password."""
|
|
|
+ enc = CryptoEngine.get()
|
|
|
+ return enc.decrypt(self._password).strip()
|
|
|
+
|
|
|
+ @property
|
|
|
+ def username(self):
|
|
|
+ """Get the current username."""
|
|
|
+ enc = CryptoEngine.get()
|
|
|
+ return enc.decrypt(self._username).strip()
|
|
|
+
|
|
|
+ @username.setter
|
|
|
+ def username(self, value):
|
|
|
+ """Set the username."""
|
|
|
+ enc = CryptoEngine.get()
|
|
|
+ self._username = enc.encrypt(value).strip()
|
|
|
+
|
|
|
+ @password.setter
|
|
|
+ def password(self, value):
|
|
|
+ """Set the Notes."""
|
|
|
+ enc = CryptoEngine.get()
|
|
|
+ self._password = enc.encrypt(value).strip()
|
|
|
+
|
|
|
+ @property
|
|
|
+ def tags(self):
|
|
|
+ enc = CryptoEngine.get()
|
|
|
+ try:
|
|
|
+ return [enc.decrypt(tag) for tag in filter(None, self._tags)]
|
|
|
+ except Exception:
|
|
|
+ return [tag for tag in filter(None, self._tags)]
|
|
|
+
|
|
|
+ @tags.setter
|
|
|
+ def tags(self, value):
|
|
|
+ self._tags = [tag for tag in value]
|
|
|
+
|
|
|
+ @property
|
|
|
+ def url(self):
|
|
|
+ """Get the current url."""
|
|
|
+ enc = CryptoEngine.get()
|
|
|
+ return enc.decrypt(self._url).strip()
|
|
|
+
|
|
|
+ @url.setter
|
|
|
+ def url(self, value):
|
|
|
+ """Set the Notes."""
|
|
|
+ enc = CryptoEngine.get()
|
|
|
+ self._url = enc.encrypt(value).strip()
|
|
|
+
|
|
|
+ @property
|
|
|
+ def notes(self):
|
|
|
+ """Get the current notes."""
|
|
|
+ enc = CryptoEngine.get()
|
|
|
+ return enc.decrypt(self._notes).strip()
|
|
|
+
|
|
|
+ @notes.setter
|
|
|
+ def notes(self, value):
|
|
|
+ """Set the Notes."""
|
|
|
+ enc = CryptoEngine.get()
|
|
|
+ self._notes = enc.encrypt(value).strip()
|