mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-04 01:19:16 +02:00
Webfinger utils
This commit is contained in:
parent
90c1d02919
commit
e793f8365f
2 changed files with 118 additions and 0 deletions
52
api/funkwhale_api/federation/webfinger.py
Normal file
52
api/funkwhale_api/federation/webfinger.py
Normal file
|
@ -0,0 +1,52 @@
|
|||
from django import forms
|
||||
from django.conf import settings
|
||||
from django.urls import reverse
|
||||
|
||||
from . import utils
|
||||
VALID_RESOURCE_TYPES = ['acct']
|
||||
|
||||
|
||||
def clean_resource(resource_string):
|
||||
if not resource_string:
|
||||
raise forms.ValidationError('Invalid resource string')
|
||||
|
||||
try:
|
||||
resource_type, resource = resource_string.split(':', 1)
|
||||
except ValueError:
|
||||
raise forms.ValidationError('Missing webfinger resource type')
|
||||
|
||||
if resource_type not in VALID_RESOURCE_TYPES:
|
||||
raise forms.ValidationError('Invalid webfinger resource type')
|
||||
|
||||
return resource_type, resource
|
||||
|
||||
|
||||
def clean_acct(acct_string):
|
||||
try:
|
||||
username, hostname = acct_string.split('@')
|
||||
except ValueError:
|
||||
raise forms.ValidationError('Invalid format')
|
||||
|
||||
if hostname != settings.FEDERATION_HOSTNAME:
|
||||
raise forms.ValidationError('Invalid hostname')
|
||||
|
||||
if username != 'service':
|
||||
raise forms.ValidationError('Invalid username')
|
||||
|
||||
return username, hostname
|
||||
|
||||
|
||||
def serialize_system_acct():
|
||||
return {
|
||||
'subject': 'acct:service@{}'.format(settings.FEDERATION_HOSTNAME),
|
||||
'aliases': [
|
||||
utils.full_url(reverse('federation:instance-actor'))
|
||||
],
|
||||
'links': [
|
||||
{
|
||||
'rel': 'self',
|
||||
'type': 'application/activity+json',
|
||||
'href': utils.full_url(reverse('federation:instance-actor')),
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue