database.py 2.9 KB

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