You can define your own key services class by implementing the interface defined in Services.py.
class PassThruAgent(ionicsdk.AgentKeyServicesBase):
def __init__(self, agentkeyservice):
self.services = agentkeyservice
self.cachedNewKeys = []
self.cacheExistingKeys = {}
self.cacheNum = 16
self.attributes = { "classifications": ["c1", "c2"], "color": ["green"] }
self.metadata = { "test-meta-key": "test-meta-value" }
self.mutableAttributes = {u"test-mutable-1": [u"test-mutable-value-1", u"test-mutable-value-2"], u"test-mutable-2":[u"test-mutable-value-1",]}
self.serverCalls = 0;
def hasactiveprofile(self):
return self.services.hasactiveprofile()
def getactiveprofile(self):
return self.services.getactiveprofile
def createkey(self, attributesdict = None, metadatadict = None, mutableAttributesdict = None):
if len(self.cachedNewKeys) == 0:
self.serverCalls += 1
self.cachedNewKeys = self.services.createkeys(self.cacheNum, self.attributes, self.metadata, self.mutableAttributes)
key = self.cachedNewKeys.pop()
self.cacheExistingKeys[key.id] = key
return key
def createkeys(self, keycount, attributesdict = None, metadatadict = None, mutableAttributesdict = None):
if len(self.cachedNewKeys) >= keycount:
keys = []
for i in range(keycount):
keys.append(self.cachedNewKeys.pop())
else:
self.serverCalls += 1
keys = self.services.createkeys(keycount, self.attributes, self.metadata, self.mutableAttributes)
for key in keys:
self.cacheExistingKeys[key.id] = key
return keys
def getkey(self, keyidstring, metadatadict = None):
key = self.cacheExistingKeys.get(keyidstring)
if key:
return key
self.serverCalls += 1
key = self.services.getkey(keyidstring, self.metadata)
self.cacheExistingKeys[key.id] = key
return key
def getkeys(self, keyidstringlist, metadatadict = None):
keys = []
unfoundIds = []
for keyid in keyidstringlist:
key = self.cacheExistingKeys.get(keyid)
if key:
keys.append(key)
else:
unfoundIds.append(keyid)
if len(unfoundIds):
self.serverCalls += 1
serverKeys = self.services.getkeys(unfoundIds, self.metadata)
keys.extend(serverKeys)
for key in serverKeys:
self.cacheExistingKeys[key.id] = key
return keys