comparison 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
comparison
equal deleted inserted replaced
3162:b5c058c7692e 3163:d10b2368684e
37 from sat.memory.params import Params 37 from sat.memory.params import Params
38 from sat.memory.disco import Discovery 38 from sat.memory.disco import Discovery
39 from sat.memory.crypto import BlockCipher 39 from sat.memory.crypto import BlockCipher
40 from sat.memory.crypto import PasswordHasher 40 from sat.memory.crypto import PasswordHasher
41 from sat.tools import config as tools_config 41 from sat.tools import config as tools_config
42 from sat.tools.common import data_format
42 import shortuuid 43 import shortuuid
43 import mimetypes 44 import mimetypes
44 import time 45 import time
45 46
46 47
1150 def paramsRegisterApp(self, xml, security_limit=C.NO_SECURITY_LIMIT, app=""): 1151 def paramsRegisterApp(self, xml, security_limit=C.NO_SECURITY_LIMIT, app=""):
1151 return self.params.paramsRegisterApp(xml, security_limit, app) 1152 return self.params.paramsRegisterApp(xml, security_limit, app)
1152 1153
1153 def setDefault(self, name, category, callback, errback=None): 1154 def setDefault(self, name, category, callback, errback=None):
1154 return self.params.setDefault(name, category, callback, errback) 1155 return self.params.setDefault(name, category, callback, errback)
1156
1157 ## Private Data ##
1158
1159 def _privateDataSet(self, namespace, key, data_s, profile_key):
1160 client = self.host.getClient(profile_key)
1161 # we accept any type
1162 data = data_format.deserialise(data_s, type_check=None)
1163 return self.storage.setPrivateValue(
1164 namespace, key, data, binary=True, profile=client.profile)
1165
1166 def _privateDataGet(self, namespace, key, profile_key):
1167 client = self.host.getClient(profile_key)
1168 d = self.storage.getPrivates(
1169 namespace, [key], binary=True, profile=client.profile)
1170 d.addCallback(lambda data_dict: data_format.serialise(data_dict.get(key)))
1171 return d
1172
1173 def _privateDataDelete(self, namespace, key, profile_key):
1174 client = self.host.getClient(profile_key)
1175 return self.storage.delPrivateValue(
1176 namespace, key, binary=True, profile=client.profile)
1155 1177
1156 ## Files ## 1178 ## Files ##
1157 1179
1158 def checkFilePermission(self, file_data, peer_jid, perms_to_check): 1180 def checkFilePermission(self, file_data, peer_jid, perms_to_check):
1159 """check that an entity has the right permission on a file 1181 """check that an entity has the right permission on a file