mirror of https://gitlab.com/bashrc2/epicyon
Move ocap files to account directories
parent
46a53072f3
commit
d83a063625
|
@ -14,17 +14,22 @@ import commentjson
|
|||
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'
|
||||
if not os.path.isdir(baseDir+'/accounts'):
|
||||
os.mkdir(baseDir+'/accounts')
|
||||
|
||||
def capabilitiesMakeDirs(baseDir: str):
|
||||
if not os.path.isdir(baseDir+'/ocap'):
|
||||
os.mkdir(baseDir+'/ocap')
|
||||
# for capabilities accepted by this instance
|
||||
if not os.path.isdir(baseDir+'/ocap/accept'):
|
||||
os.mkdir(baseDir+'/ocap/accept')
|
||||
# for capabilities granted to this instance
|
||||
if not os.path.isdir(baseDir+'/ocap/granted'):
|
||||
os.mkdir(baseDir+'/ocap/granted')
|
||||
ocDir=baseDir+'/accounts/'+nickname+'@'+domain
|
||||
if not os.path.isdir(ocDir):
|
||||
os.mkdir(ocDir)
|
||||
|
||||
ocDir=baseDir+'/accounts/'+nickname+'@'+domain+'/ocap'
|
||||
if not os.path.isdir(ocDir):
|
||||
os.mkdir(ocDir)
|
||||
|
||||
ocDir=baseDir+'/accounts/'+nickname+'@'+domain+'/ocap/'+subdir
|
||||
if not os.path.isdir(ocDir):
|
||||
os.mkdir(ocDir)
|
||||
|
||||
return baseDir+'/accounts/'+nickname+'@'+domain+'/ocap/'+subdir+'/'+actor.replace('/','#')+'.json'
|
||||
|
||||
def capabilitiesRequest(baseDir: str,httpPrefix: str,domain: str, \
|
||||
requestedActor: str, \
|
||||
|
@ -32,8 +37,6 @@ def capabilitiesRequest(baseDir: str,httpPrefix: str,domain: str, \
|
|||
# This is sent to the capabilities endpoint /caps/new
|
||||
# which could be instance wide or for a particular person
|
||||
# This could also be added to a follow activity
|
||||
capabilitiesMakeDirs(baseDir)
|
||||
|
||||
ocapId=createPassword(32)
|
||||
ocapRequest = {
|
||||
"id": httpPrefix+"://"+requestedDomain+"/caps/request/"+ocapId,
|
||||
|
@ -59,7 +62,6 @@ def capabilitiesAccept(baseDir: str,httpPrefix: str, \
|
|||
fullDomain=domain+':'+str(port)
|
||||
|
||||
# make directories to store capabilities
|
||||
capabilitiesMakeDirs(baseDir)
|
||||
ocapFilename=getOcapFilename(baseDir,nickname,fullDomain,acceptedActor,'accept')
|
||||
ocapAccept=None
|
||||
|
||||
|
@ -91,7 +93,6 @@ def capabilitiesGrantedSave(baseDir :str,nickname :str,domain :str,ocap: {}) ->
|
|||
"""
|
||||
if not ocap.get('actor'):
|
||||
return False
|
||||
capabilitiesMakeDirs(baseDir)
|
||||
ocapFilename=getOcapFilename(baseDir,nickname,domain,ocap['actor'],'granted')
|
||||
with open(ocapFilename, 'w') as fp:
|
||||
commentjson.dump(ocap, fp, indent=4, sort_keys=False)
|
||||
|
|
|
@ -6,7 +6,6 @@ __maintainer__ = "Bob Mottram"
|
|||
__email__ = "bob@freedombone.net"
|
||||
__status__ = "Production"
|
||||
|
||||
from capabilities import capabilitiesMakeDirs
|
||||
from person import createPerson
|
||||
from person import createSharedInbox
|
||||
from person import createCapabilitiesInbox
|
||||
|
@ -335,8 +334,6 @@ if not os.path.isdir(baseDir+'/accounts/capabilities@'+domain):
|
|||
print('Creating capabilities account which can sign requests')
|
||||
createCapabilitiesInbox(baseDir,'capabilities',domain,port,httpPrefix)
|
||||
|
||||
capabilitiesMakeDirs(baseDir)
|
||||
|
||||
if args.testdata:
|
||||
nickname='testuser567'
|
||||
print('Generating some test data for user: '+nickname)
|
||||
|
|
9
tests.py
9
tests.py
|
@ -313,8 +313,8 @@ def testFollowBetweenServers():
|
|||
for t in range(10):
|
||||
if os.path.isfile(bobDir+'/accounts/bob@'+bobDomain+'/followers.txt'):
|
||||
if os.path.isfile(aliceDir+'/accounts/alice@'+aliceDomain+'/following.txt'):
|
||||
if os.path.isfile(bobDir+'/ocap/accept/'+bobDomain+':'+str(bobPort)+':bob:'+httpPrefix+':##'+aliceDomain+':'+str(alicePort)+'#users#alice.json'):
|
||||
if os.path.isfile(aliceDir+'/ocap/granted/'+aliceDomain+':'+str(alicePort)+':alice:'+httpPrefix+':##'+bobDomain+':'+str(bobPort)+'#users#bob.json'):
|
||||
if os.path.isfile(bobDir+'/accounts/bob@'+bobDomain+':'+str(bobPort)+'/ocap/accept/'+httpPrefix+':##'+aliceDomain+':'+str(alicePort)+'#users#alice.json'):
|
||||
if os.path.isfile(aliceDir+'/accounts/alice@'+aliceDomain+':'+str(alicePort)+'/ocap/granted/'+httpPrefix+':##'+bobDomain+':'+str(bobPort)+'#users#bob.json'):
|
||||
break
|
||||
time.sleep(1)
|
||||
|
||||
|
@ -327,8 +327,9 @@ def testFollowBetweenServers():
|
|||
thrBob.join()
|
||||
assert thrBob.isAlive()==False
|
||||
|
||||
assert os.path.isfile(bobDir+'/ocap/accept/'+bobDomain+':'+str(bobPort)+':bob:'+httpPrefix+':##'+aliceDomain+':'+str(alicePort)+'#users#alice.json')
|
||||
assert os.path.isfile(aliceDir+'/ocap/granted/'+aliceDomain+':'+str(alicePort)+':alice:'+httpPrefix+':##'+bobDomain+':'+str(bobPort)+'#users#bob.json')
|
||||
assert os.path.isfile(bobDir+'/accounts/bob@'+bobDomain+':'+str(bobPort)+'/ocap/accept/'+httpPrefix+':##'+aliceDomain+':'+str(alicePort)+'#users#alice.json')
|
||||
assert os.path.isfile(aliceDir+'/accounts/alice@'+aliceDomain+':'+str(alicePort)+'/ocap/granted/'+httpPrefix+':##'+bobDomain+':'+str(bobPort)+'#users#bob.json')
|
||||
|
||||
assert 'alice@'+aliceDomain in open(bobDir+'/accounts/bob@'+bobDomain+'/followers.txt').read()
|
||||
assert 'bob@'+bobDomain in open(aliceDir+'/accounts/alice@'+aliceDomain+'/following.txt').read()
|
||||
|
||||
|
|
Loading…
Reference in New Issue