1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-11-04 22:40:12 +01:00

Merge branch 'config-mirrors-yml' into 'master'

establish config/mirrors.yml as a way to set up mirrors

See merge request fdroid/fdroidserver!1417
This commit is contained in:
Michael Pöhn 2023-12-07 16:34:14 +00:00
commit 2fb8fc4879
4 changed files with 64 additions and 1 deletions

View File

@ -228,6 +228,9 @@
# countryCode: BA
# - url: http://foobarfoobarfoobar.onion/fdroid
#
# The list of mirrors can also be maintained in config/mirrors.yml, a
# standalone YAML file in the optional configuration directory. In
# that case, mirrors: should be removed from this file (config.yml).
# optionally specify which identity file to use when using rsync or git over SSH

View File

@ -117,11 +117,13 @@ GITLAB_COM_PAGES_MAX_SIZE = 1000000000
ANTIFEATURES_CONFIG_NAME = 'antiFeatures'
CATEGORIES_CONFIG_NAME = 'categories'
CONFIG_CONFIG_NAME = 'config'
MIRRORS_CONFIG_NAME = 'mirrors'
RELEASECHANNELS_CONFIG_NAME = "releaseChannels"
CONFIG_NAMES = (
ANTIFEATURES_CONFIG_NAME,
CATEGORIES_CONFIG_NAME,
CONFIG_CONFIG_NAME,
MIRRORS_CONFIG_NAME,
RELEASECHANNELS_CONFIG_NAME,
)

View File

@ -29,6 +29,7 @@ import re
import shutil
import tempfile
import urllib.parse
import yaml
import zipfile
import calendar
import qrcode
@ -42,7 +43,7 @@ from . import common
from . import metadata
from . import net
from . import signindex
from fdroidserver.common import ANTIFEATURES_CONFIG_NAME, CATEGORIES_CONFIG_NAME, CONFIG_CONFIG_NAME, RELEASECHANNELS_CONFIG_NAME, DEFAULT_LOCALE, FDroidPopen, FDroidPopenBytes, load_stats_fdroid_signing_key_fingerprints
from fdroidserver.common import ANTIFEATURES_CONFIG_NAME, CATEGORIES_CONFIG_NAME, CONFIG_CONFIG_NAME, MIRRORS_CONFIG_NAME, RELEASECHANNELS_CONFIG_NAME, DEFAULT_LOCALE, FDroidPopen, FDroidPopenBytes, load_stats_fdroid_signing_key_fingerprints
from fdroidserver.exception import FDroidException, VerificationException
@ -1399,6 +1400,26 @@ def add_mirrors_to_repodict(repo_section, repodict):
if type(mirrors_config) not in (list, tuple):
mirrors_config = [mirrors_config]
mirrors_yml = Path(f'config/{MIRRORS_CONFIG_NAME}.yml')
if mirrors_yml.exists():
if mirrors_config:
raise FDroidException(
_('mirrors set twice, in config.yml and {path}!').format(
path=mirrors_yml
)
)
with mirrors_yml.open() as fp:
mirrors_config = yaml.safe_load(fp)
if not isinstance(mirrors_config, list):
msg = _('{path} is not list, but a {datatype}!')
raise TypeError(
msg.format(path=mirrors_yml, datatype=type(mirrors_config).__name__)
)
if type(mirrors_config) not in (list, tuple, set):
msg = 'In config.yml, mirrors: is not list, but a {datatype}!'
raise TypeError(msg.format(datatype=type(mirrors_config).__name__))
mirrorcheckfailed = False
mirrors = []
urls = set()

View File

@ -791,6 +791,43 @@ class IndexTest(unittest.TestCase):
with self.assertRaises(fdroidserver.exception.FDroidException):
index.add_mirrors_to_repodict('repo', repodict)
def test_load_mirrors_config_from_file(self):
# empty the dict for *.config, see setUp()
for k in sorted(common.config.keys()):
del common.config[k]
os.chdir(self.testdir)
os.mkdir('config')
primary = 'https://primary.com/fdroid/repo'
mirror = 'https://mirror.com/fdroid'
with open('config/mirrors.yml', 'w') as fp:
yaml.dump([{'url': mirror}], fp)
repodict = {'address': primary}
index.add_mirrors_to_repodict('repo', repodict)
self.assertEqual(
repodict['mirrors'],
[
{'isPrimary': True, 'url': primary},
{'url': mirror + '/repo'},
],
)
def test_error_when_load_mirrors_from_config_and_file(self):
# empty the dict for *.config, see setUp()
for k in sorted(common.config.keys()):
del common.config[k]
os.chdir(self.testdir)
os.mkdir('config')
with open('config/mirrors.yml', 'w') as fp:
yaml.dump([{'url': 'https://foo.com'}], fp)
repodict = {
'address': 'https://foo.com',
'mirrors': {'url': 'http://two/fdroid/repo'},
}
with self.assertRaises(fdroidserver.exception.FDroidException):
index.add_mirrors_to_repodict('repo', repodict)
if __name__ == "__main__":
os.chdir(os.path.dirname(__file__))