mirror of https://gitlab.com/bashrc2/epicyon
Check for capabilities storage
parent
a805a0052f
commit
994ce34a76
|
@ -140,7 +140,9 @@ def acceptFollow(baseDir: str,domain : str,messageJson: {}, \
|
||||||
# are capabilities attached? If so then store them
|
# are capabilities attached? If so then store them
|
||||||
if messageJson['object'].get('capabilities'):
|
if messageJson['object'].get('capabilities'):
|
||||||
if isinstance(messageJson['object']['capabilities'], dict):
|
if isinstance(messageJson['object']['capabilities'], dict):
|
||||||
capabilitiesGrantedSave(baseDir,messageJson['object']['capabilities'])
|
capabilitiesGrantedSave(baseDir, \
|
||||||
|
followedNickname,followedDomain, \
|
||||||
|
messageJson['object']['capabilities'])
|
||||||
|
|
||||||
if followPerson(baseDir, \
|
if followPerson(baseDir, \
|
||||||
nickname,acceptedDomain, \
|
nickname,acceptedDomain, \
|
||||||
|
|
|
@ -13,6 +13,9 @@ import json
|
||||||
import commentjson
|
import commentjson
|
||||||
from auth import createPassword
|
from auth import createPassword
|
||||||
|
|
||||||
|
def getOcapFilename(baseDir :str,nickname: str,domain: str,actor :str,subdir: str) -> str:
|
||||||
|
return baseDir+'/ocap/'+subdir+'/'+domain+':'+nickname+':'+actor.replace('/','#')+'.json'
|
||||||
|
|
||||||
def capabilitiesMakeDirs(baseDir: str):
|
def capabilitiesMakeDirs(baseDir: str):
|
||||||
if not os.path.isdir(baseDir+'/ocap'):
|
if not os.path.isdir(baseDir+'/ocap'):
|
||||||
os.mkdir(baseDir+'/ocap')
|
os.mkdir(baseDir+'/ocap')
|
||||||
|
@ -39,7 +42,7 @@ def capabilitiesRequest(baseDir: str,httpPrefix: str,domain: str, \
|
||||||
"actor": requestedActor
|
"actor": requestedActor
|
||||||
}
|
}
|
||||||
return ocapRequest
|
return ocapRequest
|
||||||
|
|
||||||
def capabilitiesAccept(baseDir: str,httpPrefix: str, \
|
def capabilitiesAccept(baseDir: str,httpPrefix: str, \
|
||||||
nickname: str,domain: str, port: int, \
|
nickname: str,domain: str, port: int, \
|
||||||
acceptedActor: str, saveToFile: bool, \
|
acceptedActor: str, saveToFile: bool, \
|
||||||
|
@ -57,12 +60,12 @@ def capabilitiesAccept(baseDir: str,httpPrefix: str, \
|
||||||
|
|
||||||
# make directories to store capabilities
|
# make directories to store capabilities
|
||||||
capabilitiesMakeDirs(baseDir)
|
capabilitiesMakeDirs(baseDir)
|
||||||
filename=baseDir+'/ocap/accept/'+acceptedActor.replace('/','#')+'.json'
|
ocapFilename=getOcapFilename(baseDir,nickname,fullDomain,acceptedActor,'accept')
|
||||||
ocapAccept=None
|
ocapAccept=None
|
||||||
|
|
||||||
# if the capability already exists then load it from file
|
# if the capability already exists then load it from file
|
||||||
if os.path.isfile(filename):
|
if os.path.isfile(ocapFilename):
|
||||||
with open(filename, 'r') as fp:
|
with open(ocapFilename, 'r') as fp:
|
||||||
ocapAccept=commentjson.load(fp)
|
ocapAccept=commentjson.load(fp)
|
||||||
# otherwise create a new capability
|
# otherwise create a new capability
|
||||||
if not ocapAccept:
|
if not ocapAccept:
|
||||||
|
@ -78,18 +81,18 @@ def capabilitiesAccept(baseDir: str,httpPrefix: str, \
|
||||||
ocapAccept['actor']=httpPrefix+"://"+fullDomain+'/users/'+nickname
|
ocapAccept['actor']=httpPrefix+"://"+fullDomain+'/users/'+nickname
|
||||||
|
|
||||||
if saveToFile:
|
if saveToFile:
|
||||||
with open(filename, 'w') as fp:
|
with open(ocapFilename, 'w') as fp:
|
||||||
commentjson.dump(ocapAccept, fp, indent=4, sort_keys=False)
|
commentjson.dump(ocapAccept, fp, indent=4, sort_keys=False)
|
||||||
return ocapAccept
|
return ocapAccept
|
||||||
|
|
||||||
def capabilitiesGrantedSave(baseDir :str,ocap: {}) -> bool:
|
def capabilitiesGrantedSave(baseDir :str,nickname :str,domain :str,ocap: {}) -> bool:
|
||||||
"""A capabilities accept is received, so stor it for
|
"""A capabilities accept is received, so stor it for
|
||||||
reference when sending to the actor
|
reference when sending to the actor
|
||||||
"""
|
"""
|
||||||
if not ocap.get('actor'):
|
if not ocap.get('actor'):
|
||||||
return False
|
return False
|
||||||
filename=baseDir+'/ocap/granted/'+ocap['actor'].replace('/','#')+'.json'
|
ocapFilename=getOcapFilename(baseDir,nickname,fullDomain,ocap['actor'],'granted')
|
||||||
with open(filename, 'w') as fp:
|
with open(ocapFilename, 'w') as fp:
|
||||||
commentjson.dump(ocap, fp, indent=4, sort_keys=False)
|
commentjson.dump(ocap, fp, indent=4, sort_keys=False)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
11
inbox.py
11
inbox.py
|
@ -24,6 +24,7 @@ from pprint import pprint
|
||||||
from cache import getPersonFromCache
|
from cache import getPersonFromCache
|
||||||
from cache import storePersonInCache
|
from cache import storePersonInCache
|
||||||
from acceptreject import receiveAcceptReject
|
from acceptreject import receiveAcceptReject
|
||||||
|
from capabilities import getOcapFilename
|
||||||
|
|
||||||
def getPersonPubKey(session,personUrl: str,personCache: {},debug: bool) -> str:
|
def getPersonPubKey(session,personUrl: str,personCache: {},debug: bool) -> str:
|
||||||
if not personUrl:
|
if not personUrl:
|
||||||
|
@ -126,6 +127,8 @@ def savePostToInboxQueue(baseDir: str,httpPrefix: str,nickname: str, domain: str
|
||||||
sharedInboxItem=True
|
sharedInboxItem=True
|
||||||
|
|
||||||
newQueueItem = {
|
newQueueItem = {
|
||||||
|
'nickname': nickname,
|
||||||
|
'domain': domain,
|
||||||
'sharedInbox': sharedInboxItem,
|
'sharedInbox': sharedInboxItem,
|
||||||
'published': published,
|
'published': published,
|
||||||
'host': host,
|
'host': host,
|
||||||
|
@ -190,10 +193,14 @@ def runInboxQueue(baseDir: str,httpPrefix: str,sendThreads: [],postLog: [],cache
|
||||||
os.remove(queueFilename)
|
os.remove(queueFilename)
|
||||||
queue.pop(0)
|
queue.pop(0)
|
||||||
continue
|
continue
|
||||||
ocapFilename=baseDir+'/ocap/accept/'+queueJson['post']['actor'].replace('/','#')+'.json'
|
ocapFilename= \
|
||||||
|
getOcapFilename(baseDir, \
|
||||||
|
queueJson['nickname'],queueJson['domain'], \
|
||||||
|
queueJson['post']['actor'],'accept')
|
||||||
if not os.path.isfile(ocapFilename):
|
if not os.path.isfile(ocapFilename):
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: capabilities for '+queueJson['post']['actor']+' do not exist')
|
print('DEBUG: capabilities for '+ \
|
||||||
|
queueJson['post']['actor']+' do not exist')
|
||||||
os.remove(queueFilename)
|
os.remove(queueFilename)
|
||||||
queue.pop(0)
|
queue.pop(0)
|
||||||
continue
|
continue
|
||||||
|
|
6
tests.py
6
tests.py
|
@ -313,7 +313,8 @@ def testFollowBetweenServers():
|
||||||
for t in range(10):
|
for t in range(10):
|
||||||
if os.path.isfile(bobDir+'/accounts/bob@'+bobDomain+'/followers.txt'):
|
if os.path.isfile(bobDir+'/accounts/bob@'+bobDomain+'/followers.txt'):
|
||||||
if os.path.isfile(aliceDir+'/accounts/alice@'+aliceDomain+'/following.txt'):
|
if os.path.isfile(aliceDir+'/accounts/alice@'+aliceDomain+'/following.txt'):
|
||||||
break
|
if os.path.isfile(bobDir+'/ocap/accept/'+bobDomain+':'+str(bobPort)+':bob:'+httpPrefix+':##'+aliceDomain+':'+str(alicePort)+'#users#alice.json'):
|
||||||
|
break
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
# stop the servers
|
# stop the servers
|
||||||
|
@ -325,11 +326,12 @@ def testFollowBetweenServers():
|
||||||
thrBob.join()
|
thrBob.join()
|
||||||
assert thrBob.isAlive()==False
|
assert thrBob.isAlive()==False
|
||||||
|
|
||||||
|
assert os.path.isfile(bobDir+'/ocap/accept/'+bobDomain+':'+str(bobPort)+':bob:'+httpPrefix+':##'+aliceDomain+':'+str(alicePort)+'#users#alice.json')
|
||||||
assert 'alice@'+aliceDomain in open(bobDir+'/accounts/bob@'+bobDomain+'/followers.txt').read()
|
assert 'alice@'+aliceDomain in open(bobDir+'/accounts/bob@'+bobDomain+'/followers.txt').read()
|
||||||
assert 'bob@'+bobDomain in open(aliceDir+'/accounts/alice@'+aliceDomain+'/following.txt').read()
|
assert 'bob@'+bobDomain in open(aliceDir+'/accounts/alice@'+aliceDomain+'/following.txt').read()
|
||||||
|
|
||||||
os.chdir(baseDir)
|
os.chdir(baseDir)
|
||||||
shutil.rmtree(baseDir+'/.tests')
|
#shutil.rmtree(baseDir+'/.tests')
|
||||||
|
|
||||||
def testFollowersOfPerson():
|
def testFollowersOfPerson():
|
||||||
print('testFollowersOfPerson')
|
print('testFollowersOfPerson')
|
||||||
|
|
Loading…
Reference in New Issue