database.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #============================================================================
  2. # This file is part of Pwman3.
  3. #
  4. # Pwman3 is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License, version 2
  6. # as published by the Free Software Foundation;
  7. #
  8. # Pwman3 is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with Pwman3; if not, write to the Free Software
  15. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. #============================================================================
  17. # Copyright (C) 2012 Oz Nahum <nahumoz@gmail.com>
  18. #============================================================================
  19. # Copyright (C) 2006 Ivan Kelly <ivan@ivankelly.net>
  20. #============================================================================
  21. from pwman.util.crypto import CryptoEngine
  22. class DatabaseException(Exception):
  23. pass # prage: no cover
  24. class Database(object):
  25. def __init__(self):
  26. self._filtertags = []
  27. def open(self):
  28. """
  29. Open the database, by calling the _open method of the
  30. class inherited for the specific database.
  31. When done validation that the file is OK, check if it has
  32. encryption key, by calling
  33. enc = CryptoEngine.get()
  34. key = self.loadkey()
  35. """
  36. self._open()
  37. enc = CryptoEngine.get()
  38. key = self.loadkey()
  39. if key is not None:
  40. enc.set_cryptedkey(key)
  41. else:
  42. self.get_user_password()
  43. def close(self):
  44. pass # pragma: no cover
  45. def get_user_password(self):
  46. """
  47. get the databases password from the user
  48. """
  49. enc = CryptoEngine.get()
  50. newkey = enc.changepassword()
  51. return self.savekey(newkey)
  52. def changepassword(self):
  53. """
  54. Change the databases password.
  55. """
  56. enc = CryptoEngine.get()
  57. newkey = enc.changepassword()
  58. return newkey
  59. # self.savekey(newkey)
  60. def listtags(self, all=False):
  61. pass # pragma: no cover
  62. def currenttags(self):
  63. return self._filtertags
  64. def filter(self, tags):
  65. for tag in tags:
  66. if not (tag in self._filtertags):
  67. self._filtertags.append(tag)
  68. def clearfilter(self):
  69. self._filtertags = []
  70. def getnodes(self, ids):
  71. pass # pragma: no cover
  72. def addnodes(self, nodes):
  73. pass # pragma: no cover
  74. def editnode(self, id, node):
  75. pass # pragma: no cover
  76. def removenodes(self, nodes):
  77. pass # pragma: no cover
  78. def listnodes(self):
  79. pass # pragma: no cover
  80. def savekey(self, key):
  81. pass # pragma: no cover
  82. def loadkey(self):
  83. pass # pragma: no cover