Mercurial > libervia-backend
diff sat/memory/memory.py @ 3163:d10b2368684e
bridge: added methods to let frontends store/retrieve/delete private data
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 10 Feb 2020 22:01:53 +0100 |
parents | 330a5f1d9eea |
children | 39d7327583e1 |
line wrap: on
line diff
--- a/sat/memory/memory.py Sun Feb 09 23:56:42 2020 +0100 +++ b/sat/memory/memory.py Mon Feb 10 22:01:53 2020 +0100 @@ -39,6 +39,7 @@ from sat.memory.crypto import BlockCipher from sat.memory.crypto import PasswordHasher from sat.tools import config as tools_config +from sat.tools.common import data_format import shortuuid import mimetypes import time @@ -1153,6 +1154,27 @@ def setDefault(self, name, category, callback, errback=None): return self.params.setDefault(name, category, callback, errback) + ## Private Data ## + + def _privateDataSet(self, namespace, key, data_s, profile_key): + client = self.host.getClient(profile_key) + # we accept any type + data = data_format.deserialise(data_s, type_check=None) + return self.storage.setPrivateValue( + namespace, key, data, binary=True, profile=client.profile) + + def _privateDataGet(self, namespace, key, profile_key): + client = self.host.getClient(profile_key) + d = self.storage.getPrivates( + namespace, [key], binary=True, profile=client.profile) + d.addCallback(lambda data_dict: data_format.serialise(data_dict.get(key))) + return d + + def _privateDataDelete(self, namespace, key, profile_key): + client = self.host.getClient(profile_key) + return self.storage.delPrivateValue( + namespace, key, binary=True, profile=client.profile) + ## Files ## def checkFilePermission(self, file_data, peer_jid, perms_to_check):