Detecting group handle

merge-requests/26/head
Bob Mottram 2021-07-30 14:00:23 +01:00
parent 70240c84b1
commit 40f0aac017
18 changed files with 97 additions and 97 deletions

View File

@ -235,7 +235,7 @@ def sendAnnounceViaServer(baseDir: str, session,
# lookup the inbox for the To handle
wfRequest = webfingerHandle(session, handle, httpPrefix,
cachedWebfingers,
fromDomain, projectVersion, debug)
fromDomain, projectVersion, debug, False)
if not wfRequest:
if debug:
print('DEBUG: announce webfinger failed for ' + handle)
@ -315,7 +315,7 @@ def sendUndoAnnounceViaServer(baseDir: str, session,
# lookup the inbox for the To handle
wfRequest = webfingerHandle(session, handle, httpPrefix,
cachedWebfingers,
domain, projectVersion, debug)
domain, projectVersion, debug, False)
if not wfRequest:
if debug:
print('DEBUG: undo announce webfinger failed for ' + handle)

View File

@ -107,7 +107,7 @@ def sendAvailabilityViaServer(baseDir: str, session,
# lookup the inbox for the To handle
wfRequest = webfingerHandle(session, handle, httpPrefix,
cachedWebfingers,
domain, projectVersion, debug)
domain, projectVersion, debug, False)
if not wfRequest:
if debug:
print('DEBUG: availability webfinger failed for ' + handle)

View File

@ -376,7 +376,7 @@ def sendBookmarkViaServer(baseDir: str, session,
# lookup the inbox for the To handle
wfRequest = webfingerHandle(session, handle, httpPrefix,
cachedWebfingers,
domain, projectVersion, debug)
domain, projectVersion, debug, False)
if not wfRequest:
if debug:
print('DEBUG: bookmark webfinger failed for ' + handle)
@ -461,7 +461,7 @@ def sendUndoBookmarkViaServer(baseDir: str, session,
# lookup the inbox for the To handle
wfRequest = webfingerHandle(session, handle, httpPrefix,
cachedWebfingers,
domain, projectVersion, debug)
domain, projectVersion, debug, False)
if not wfRequest:
if debug:
print('DEBUG: unbookmark webfinger failed for ' + handle)

View File

@ -57,7 +57,7 @@ def sendDeleteViaServer(baseDir: str, session,
# lookup the inbox for the To handle
wfRequest = \
webfingerHandle(session, handle, httpPrefix, cachedWebfingers,
fromDomain, projectVersion, debug)
fromDomain, projectVersion, debug, False)
if not wfRequest:
if debug:
print('DEBUG: delete webfinger failed for ' + handle)

View File

@ -1765,7 +1765,7 @@ if args.followers:
handle = nickname + '@' + domain
wfRequest = webfingerHandle(session, handle,
httpPrefix, cachedWebfingers,
None, __version__, debug)
None, __version__, debug, False)
if not wfRequest:
print('Unable to webfinger ' + handle)
sys.exit()

View File

@ -984,7 +984,7 @@ def sendFollowRequestViaServer(baseDir: str, session,
# lookup the inbox for the To handle
wfRequest = \
webfingerHandle(session, handle, httpPrefix, cachedWebfingers,
fromDomain, projectVersion, debug)
fromDomain, projectVersion, debug, False)
if not wfRequest:
if debug:
print('DEBUG: follow request webfinger failed for ' + handle)
@ -1075,7 +1075,7 @@ def sendUnfollowRequestViaServer(baseDir: str, session,
# lookup the inbox for the To handle
wfRequest = \
webfingerHandle(session, handle, httpPrefix, cachedWebfingers,
fromDomain, projectVersion, debug)
fromDomain, projectVersion, debug, False)
if not wfRequest:
if debug:
print('DEBUG: unfollow webfinger failed for ' + handle)

View File

@ -169,7 +169,7 @@ def sendLikeViaServer(baseDir: str, session,
# lookup the inbox for the To handle
wfRequest = webfingerHandle(session, handle, httpPrefix,
cachedWebfingers,
fromDomain, projectVersion, debug)
fromDomain, projectVersion, debug, False)
if not wfRequest:
if debug:
print('DEBUG: like webfinger failed for ' + handle)
@ -251,7 +251,7 @@ def sendUndoLikeViaServer(baseDir: str, session,
# lookup the inbox for the To handle
wfRequest = webfingerHandle(session, handle, httpPrefix,
cachedWebfingers,
fromDomain, projectVersion, debug)
fromDomain, projectVersion, debug, False)
if not wfRequest:
if debug:
print('DEBUG: unlike webfinger failed for ' + handle)

View File

@ -58,7 +58,7 @@ def _updateMovedHandle(baseDir: str, nickname: str, domain: str,
handle = handle[1:]
wfRequest = webfingerHandle(session, handle,
httpPrefix, cachedWebfingers,
None, __version__, debug)
None, __version__, debug, False)
if not wfRequest:
print('updateMovedHandle unable to webfinger ' + handle)
return ctr

View File

@ -53,6 +53,7 @@ from utils import getImageExtensions
from utils import isImageFile
from utils import acctDir
from utils import getUserPaths
from utils import getGroupPaths
from session import createSession
from session import getJson
from webfinger import webfingerHandle
@ -1213,7 +1214,7 @@ def getActorJson(hostDomain: str, handle: str, http: bool, gnunet: bool,
if debug:
print('getActorJson for ' + handle)
originalActor = handle
requiresWebfinger = True
groupAccount = False
# try to determine the users path
detectedUsersPath = _detectUsersPath(handle)
@ -1221,9 +1222,9 @@ def getActorJson(hostDomain: str, handle: str, http: bool, gnunet: bool,
detectedUsersPath in handle or \
handle.startswith('http') or \
handle.startswith('hyper'):
if detectedUsersPath == '/c/':
# requiresWebfinger = False
requiresWebfinger = True
groupPaths = getGroupPaths()
if detectedUsersPath in groupPaths:
groupAccount = True
# format: https://domain/@nick
originalHandle = handle
if not hasUsersPath(originalHandle):
@ -1265,8 +1266,7 @@ def getActorJson(hostDomain: str, handle: str, http: bool, gnunet: bool,
elif handle.startswith('!'):
# handle for a group
handle = handle[1:]
# requiresWebfinger = False
requiresWebfinger = True
groupAccount = True
if '@' not in handle:
if not quiet:
print('getActorJsonSyntax: --actor nickname@domain')
@ -1296,39 +1296,34 @@ def getActorJson(hostDomain: str, handle: str, http: bool, gnunet: bool,
nickname = domain
handle = nickname + '@' + domain
if requiresWebfinger:
# person actor requires webfinger
wfRequest = webfingerHandle(session, handle,
httpPrefix, cachedWebfingers,
None, __version__, debug)
if not wfRequest:
if not quiet:
print('getActorJson Unable to webfinger ' + handle)
return None, None
if not isinstance(wfRequest, dict):
if not quiet:
print('getActorJson Webfinger for ' + handle +
' did not return a dict. ' + str(wfRequest))
return None, None
wfRequest = webfingerHandle(session, handle,
httpPrefix, cachedWebfingers,
None, __version__, debug,
groupAccount)
if not wfRequest:
if not quiet:
pprint(wfRequest)
print('getActorJson Unable to webfinger ' + handle)
return None, None
if not isinstance(wfRequest, dict):
if not quiet:
print('getActorJson Webfinger for ' + handle +
' did not return a dict. ' + str(wfRequest))
return None, None
personUrl = None
if wfRequest.get('errors'):
if not quiet or debug:
print('getActorJson wfRequest error: ' +
str(wfRequest['errors']))
if hasUsersPath(handle):
personUrl = originalActor
else:
if debug:
print('No users path in ' + handle)
return None, None
else:
# group actor only needs a json http GET
originalActor = httpPrefix + '://' + domain + '/c/' + nickname
personUrl = originalActor
if not quiet:
pprint(wfRequest)
personUrl = None
if wfRequest.get('errors'):
if not quiet or debug:
print('getActorJson wfRequest error: ' +
str(wfRequest['errors']))
if hasUsersPath(handle):
personUrl = originalActor
else:
if debug:
print('No users path in ' + handle)
return None, None
profileStr = 'https://www.w3.org/ns/activitystreams'
headersList = (

2
pgp.py
View File

@ -547,7 +547,7 @@ def pgpPublicKeyUpload(baseDir: str, session,
# lookup the inbox for the To handle
wfRequest = \
webfingerHandle(session, handle, httpPrefix, cachedWebfingers,
domain, __version__, debug)
domain, __version__, debug, False)
if not wfRequest:
if debug:
print('DEBUG: pgp actor update webfinger failed for ' +

View File

@ -1957,7 +1957,7 @@ def sendPost(projectVersion: str,
# lookup the inbox for the To handle
wfRequest = webfingerHandle(session, handle, httpPrefix,
cachedWebfingers,
domain, projectVersion, debug)
domain, projectVersion, debug, False)
if not wfRequest:
return 1
if not isinstance(wfRequest, dict):
@ -2077,7 +2077,7 @@ def sendPostViaServer(projectVersion: str,
# lookup the inbox for the To handle
wfRequest = \
webfingerHandle(session, handle, httpPrefix, cachedWebfingers,
fromDomain, projectVersion, debug)
fromDomain, projectVersion, debug, False)
if not wfRequest:
if debug:
print('DEBUG: post webfinger failed for ' + handle)
@ -2275,7 +2275,7 @@ def sendSignedJson(postJsonObject: {}, session, baseDir: str,
# lookup the inbox for the To handle
wfRequest = webfingerHandle(session, handle, httpPrefix, cachedWebfingers,
domain, projectVersion, debug)
domain, projectVersion, debug, False)
if not wfRequest:
if debug:
print('DEBUG: webfinger for ' + handle + ' failed')
@ -2624,7 +2624,7 @@ def _hasSharedInbox(session, httpPrefix: str, domain: str,
]
for handle in tryHandles:
wfRequest = webfingerHandle(session, handle, httpPrefix, {},
None, __version__, debug)
None, __version__, debug, False)
if wfRequest:
if isinstance(wfRequest, dict):
if not wfRequest.get('errors'):
@ -3594,7 +3594,7 @@ def getPublicPostsOfPerson(baseDir: str, nickname: str, domain: str,
handle = httpPrefix + "://" + domainFull + "/@" + nickname
wfRequest = \
webfingerHandle(session, handle, httpPrefix, cachedWebfingers,
domain, projectVersion, debug)
domain, projectVersion, debug, False)
if not wfRequest:
sys.exit()
if not isinstance(wfRequest, dict):
@ -3637,7 +3637,7 @@ def getPublicPostDomains(session, baseDir: str, nickname: str, domain: str,
handle = httpPrefix + "://" + domainFull + "/@" + nickname
wfRequest = \
webfingerHandle(session, handle, httpPrefix, cachedWebfingers,
domain, projectVersion, debug)
domain, projectVersion, debug, False)
if not wfRequest:
return domainList
if not isinstance(wfRequest, dict):
@ -3717,7 +3717,7 @@ def getPublicPostInfo(session, baseDir: str, nickname: str, domain: str,
handle = httpPrefix + "://" + domainFull + "/@" + nickname
wfRequest = \
webfingerHandle(session, handle, httpPrefix, cachedWebfingers,
domain, projectVersion, debug)
domain, projectVersion, debug, False)
if not wfRequest:
return {}
if not isinstance(wfRequest, dict):
@ -4214,7 +4214,7 @@ def sendBlockViaServer(baseDir: str, session,
# lookup the inbox for the To handle
wfRequest = webfingerHandle(session, handle, httpPrefix,
cachedWebfingers,
fromDomain, projectVersion, debug)
fromDomain, projectVersion, debug, False)
if not wfRequest:
if debug:
print('DEBUG: block webfinger failed for ' + handle)
@ -4290,7 +4290,7 @@ def sendMuteViaServer(baseDir: str, session,
# lookup the inbox for the To handle
wfRequest = webfingerHandle(session, handle, httpPrefix,
cachedWebfingers,
fromDomain, projectVersion, debug)
fromDomain, projectVersion, debug, False)
if not wfRequest:
if debug:
print('DEBUG: mute webfinger failed for ' + handle)
@ -4371,7 +4371,7 @@ def sendUndoMuteViaServer(baseDir: str, session,
# lookup the inbox for the To handle
wfRequest = webfingerHandle(session, handle, httpPrefix,
cachedWebfingers,
fromDomain, projectVersion, debug)
fromDomain, projectVersion, debug, False)
if not wfRequest:
if debug:
print('DEBUG: undo mute webfinger failed for ' + handle)
@ -4457,7 +4457,7 @@ def sendUndoBlockViaServer(baseDir: str, session,
# lookup the inbox for the To handle
wfRequest = webfingerHandle(session, handle, httpPrefix,
cachedWebfingers,
fromDomain, projectVersion, debug)
fromDomain, projectVersion, debug, False)
if not wfRequest:
if debug:
print('DEBUG: unblock webfinger failed for ' + handle)

View File

@ -509,7 +509,7 @@ def sendShareViaServer(baseDir, session,
wfRequest = \
webfingerHandle(session, handle, httpPrefix,
cachedWebfingers,
fromDomain, projectVersion, debug)
fromDomain, projectVersion, debug, False)
if not wfRequest:
if debug:
print('DEBUG: share webfinger failed for ' + handle)
@ -610,7 +610,7 @@ def sendUndoShareViaServer(baseDir: str, session,
# lookup the inbox for the To handle
wfRequest = \
webfingerHandle(session, handle, httpPrefix, cachedWebfingers,
fromDomain, projectVersion, debug)
fromDomain, projectVersion, debug, False)
if not wfRequest:
if debug:
print('DEBUG: unshare webfinger failed for ' + handle)

View File

@ -208,7 +208,7 @@ def sendSkillViaServer(baseDir: str, session, nickname: str, password: str,
wfRequest = \
webfingerHandle(session, handle, httpPrefix,
cachedWebfingers,
domain, projectVersion, debug)
domain, projectVersion, debug, False)
if not wfRequest:
if debug:
print('DEBUG: skill webfinger failed for ' + handle)

View File

@ -54,7 +54,7 @@ def instancesGraph(baseDir: str, handles: str,
wfRequest = \
webfingerHandle(session, handle, httpPrefix,
cachedWebfingers,
domain, projectVersion, debug)
domain, projectVersion, debug, False)
if not wfRequest:
return dotGraphStr + '}\n'
if not isinstance(wfRequest, dict):

View File

@ -979,6 +979,13 @@ def getUserPaths() -> []:
return ('/users/', '/profile/', '/accounts/', '/channel/', '/u/', '/c/')
def getGroupPaths() -> []:
"""Returns possible group paths
e.g. /c/groupname
"""
return ('/c/')
def getDomainFromActor(actor: str) -> (str, int):
"""Returns the domain name from an actor url
"""

View File

@ -1183,7 +1183,7 @@ def individualPostAsHtml(allowDownloads: bool,
postActorWf = \
webfingerHandle(session, postActorHandle, httpPrefix,
cachedWebfingers,
domain, __version__, False)
domain, __version__, False, False)
avatarUrl2 = None
displayName = None

View File

@ -2053,7 +2053,7 @@ def _individualFollowAsHtml(translate: {},
followUrlWf = \
webfingerHandle(session, followUrlHandle, httpPrefix,
cachedWebfingers,
domain, __version__, debug)
domain, __version__, debug, False)
(inboxUrl, pubKeyId, pubKey,
fromPersonId, sharedInbox,

View File

@ -19,13 +19,15 @@ from utils import saveJson
from utils import getProtocolPrefixes
from utils import removeDomainPort
from utils import getUserPaths
from utils import getGroupPaths
def _parseHandle(handle: str) -> (str, str):
def _parseHandle(handle: str) -> (str, str, bool):
"""Parses a handle and returns nickname and domain
"""
groupAccount = False
if '.' not in handle:
return None, None
return None, None, False
prefixes = getProtocolPrefixes()
handleStr = handle
for prefix in prefixes:
@ -34,27 +36,33 @@ def _parseHandle(handle: str) -> (str, str):
# try domain/@nick
if '/@' in handle:
domain, nickname = handleStr.split('/@')
return nickname, domain
return nickname, domain, False
# try nick@domain
if '@' in handle:
if handle.startswith('!'):
handle = handle[1:]
groupAccount = True
nickname, domain = handle.split('@')
return nickname, domain
return nickname, domain, groupAccount
# try for different /users/ paths
usersPaths = getUserPaths()
groupPaths = getGroupPaths()
for possibleUsersPath in usersPaths:
if possibleUsersPath in handle:
if possibleUsersPath in groupPaths:
groupAccount = True
domain, nickname = handleStr.split(possibleUsersPath)
return nickname, domain
return nickname, domain, groupAccount
return None, None
return None, None, False
def webfingerHandle(session, handle: str, httpPrefix: str,
cachedWebfingers: {},
fromDomain: str, projectVersion: str,
debug: bool) -> {}:
debug: bool, groupAccount: bool) -> {}:
"""Gets webfinger result for the given ActivityPub handle
"""
if not session:
@ -62,9 +70,11 @@ def webfingerHandle(session, handle: str, httpPrefix: str,
print('WARN: No session specified for webfingerHandle')
return None
nickname, domain = _parseHandle(handle)
nickname, domain, grpAccount = _parseHandle(handle)
if not nickname:
return None
if grpAccount:
groupAccount = True
wfDomain = removeDomainPort(domain)
wfHandle = nickname + '@' + wfDomain
@ -77,34 +87,22 @@ def webfingerHandle(session, handle: str, httpPrefix: str,
hdr = {
'Accept': 'application/jrd+json'
}
par = {
'resource': 'acct:{}'.format(wfHandle)
}
success = False
if not groupAccount:
par = {
'resource': 'acct:{}'.format(wfHandle)
}
else:
par = {
'resource': 'group:{}'.format(wfHandle)
}
try:
result = \
getJson(session, url, hdr, par,
debug, projectVersion,
httpPrefix, fromDomain)
if result:
success = True
except Exception as e:
print('ERROR: webfingerHandle acct ' + str(e))
pass
if not success:
par = {
'resource': 'group:{}'.format(wfHandle)
}
try:
result = \
getJson(session, url, hdr, par,
debug, projectVersion,
httpPrefix, fromDomain)
if result:
success = True
except Exception as e:
print('ERROR: webfingerHandle group ' + str(e))
return None
print('ERROR: webfingerHandle ' + str(e))
return None
if result:
storeWebfingerInCache(wfHandle, result, cachedWebfingers)