mongodb.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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) 2015 Oz Nahum Tiram <nahumoz@gmail.com>
  18. # ============================================================================
  19. from pwman.data.database import Database, __DB_FORMAT__
  20. import pymongo
  21. class MongoDB(Database):
  22. @classmethod
  23. def check_db_version(cls, dburi):
  24. pass
  25. def __init__(self, mongodb_uri, dbformat=__DB_FORMAT__):
  26. self.uri = mongodb_uri
  27. def _open(self):
  28. self._con = pymongo.Connection(self.uri)
  29. self._db = self._con.get_default_database()
  30. def getnodes(self, ids):
  31. pass
  32. def listnodes(self, filter=None):
  33. pass
  34. def add_node(self, node):
  35. pass
  36. def listtags(self):
  37. pass
  38. def editnode(self, nid, **kwargs):
  39. pass
  40. def removenodes(self, nid):
  41. pass
  42. def fetch_crypto_info(self):
  43. pass
  44. def savekey(self, key):
  45. coll = self._db['crypto']
  46. salt, digest = key.split('$6$')
  47. coll.insert({'salt': salt, 'key': digest})
  48. def loadkey(self):
  49. coll = self._db['crypto']
  50. key = coll.find_one({}, {'_id': 0})
  51. key = key['salt'] + '$6$' + key['key']
  52. return key
  53. def close(self):
  54. pass