Added FUNKWHALE_HOSTNAME and FEDERATION_HOSTNAME settings

merge-requests/154/head
Eliot Berriot 2018-03-29 00:00:01 +02:00
rodzic 588da6ff33
commit 90c1d02919
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: DD6965E2476E5C27
3 zmienionych plików z 36 dodań i 1 usunięć

Wyświetl plik

@ -10,6 +10,7 @@ https://docs.djangoproject.com/en/dev/ref/settings/
"""
from __future__ import absolute_import, unicode_literals
from urllib.parse import urlsplit
import os
import environ
from funkwhale_api import __version__
@ -24,8 +25,13 @@ try:
except FileNotFoundError:
pass
ALLOWED_HOSTS = env.list('DJANGO_ALLOWED_HOSTS')
FUNKWHALE_URL = env('FUNKWHALE_URL')
FUNKWHALE_HOSTNAME = urlsplit(FUNKWHALE_URL).netloc
FEDERATION_ENABLED = env.bool('FEDERATION_ENABLED', default=True)
FEDERATION_HOSTNAME = env('FEDERATION_HOSTNAME', default=FUNKWHALE_HOSTNAME)
ALLOWED_HOSTS = env.list('DJANGO_ALLOWED_HOSTS')
# APP CONFIGURATION
# ------------------------------------------------------------------------------
@ -395,4 +401,5 @@ ACCOUNT_USERNAME_BLACKLIST = [
'owner',
'superuser',
'staff',
'service',
] + env.list('ACCOUNT_USERNAME_BLACKLIST', default=[])

Wyświetl plik

@ -0,0 +1,14 @@
from django.conf import settings
def full_url(path):
"""
Given a relative path, return a full url usable for federation purpose
"""
root = settings.FUNKWHALE_URL
if path.startswith('/') and root.endswith('/'):
return root + path[1:]
elif not path.startswith('/') and not root.endswith('/'):
return root + '/' + path
else:
return root + path

Wyświetl plik

@ -0,0 +1,14 @@
import pytest
from funkwhale_api.federation import utils
@pytest.mark.parametrize('url,path,expected', [
('http://test.com', '/hello', 'http://test.com/hello'),
('http://test.com/', 'hello', 'http://test.com/hello'),
('http://test.com/', '/hello', 'http://test.com/hello'),
('http://test.com', 'hello', 'http://test.com/hello'),
])
def test_full_url(settings, url, path, expected):
settings.FUNKWHALE_URL = url
assert utils.full_url(path) == expected