database.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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_engine import CryptoEngine
  22. __DB_FORMAT__ = 0.6
  23. class DatabaseException(Exception):
  24. pass # prage: no cover
  25. class Database(object):
  26. def open(self, dbver=None):
  27. """
  28. Open the database, by calling the _open method of the
  29. class inherited for the specific database.
  30. When done validation that the file is OK, check if it has
  31. encryption key, by calling
  32. enc = CryptoEngine.get()
  33. key = self.loadkey()
  34. """
  35. self._open()
  36. enc = CryptoEngine.get()
  37. key = self.loadkey()
  38. if key is not None:
  39. enc.set_cryptedkey(key)
  40. else:
  41. self.get_user_password()
  42. def close(self):
  43. pass # pragma: no cover
  44. def get_user_password(self):
  45. """
  46. get the databases password from the user
  47. """
  48. enc = CryptoEngine.get()
  49. newkey = enc.changepassword()
  50. return self.savekey(newkey)
  51. def changepassword(self):
  52. """
  53. Change the databases password.
  54. """
  55. # TODO: call the converter here ...
  56. # nodeids = self.listnodes()
  57. # nodes = self.getnodes(nodeids)
  58. # enc = CryptoEngine.get()
  59. # oldkey = enc.get_cryptedkey()
  60. # newkey = enc.changepassword()
  61. # return newkey
  62. def listtags(self, all=False):
  63. pass # pragma: no cover
  64. #def currenttags(self):
  65. # return self._filtertags
  66. def addnodes(self, nodes):
  67. pass # pragma: no cover
  68. def editnode(self, id, node):
  69. pass # pragma: no cover
  70. def removenodes(self, nodes):
  71. pass # pragma: no cover
  72. def listnodes(self):
  73. pass # pragma: no cover
  74. def savekey(self, key):
  75. pass # pragma: no cover
  76. def loadkey(self):
  77. pass # pragma: no cover