|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# This file is part of Invenio. |
| 3 | +# Copyright (C) 2025 CERN. |
| 4 | +# |
| 5 | +# Invenio is free software; you can redistribute it and/or modify it |
| 6 | +# under the terms of the MIT License; see LICENSE file for more details. |
| 7 | + |
| 8 | +"""You can use these options to configure the Invenio-VCS module. |
| 9 | +
|
| 10 | +Other than ``VCS_PROVIDERS``, they are all optional and configured with reasonable defaults. |
| 11 | +""" |
| 12 | + |
| 13 | +from typing import TYPE_CHECKING |
| 14 | + |
| 15 | +from flask import current_app |
| 16 | + |
| 17 | +if TYPE_CHECKING: |
| 18 | + from invenio_vcs.providers import RepositoryServiceProviderFactory |
| 19 | + |
| 20 | +VCS_PROVIDERS = [] |
| 21 | +"""The list of RepositoryProviderFactory instances. |
| 22 | +
|
| 23 | +These will be visible to the user in their settings and they will be able to sync repositories |
| 24 | +from all of them. Multiple instances of different providers as well as of the same provider |
| 25 | +can be combined in this list, but each provider must have a unique ``id`` and ``credentials_key``. |
| 26 | +""" |
| 27 | + |
| 28 | +VCS_PROVIDER_CONFIG_DICT = {} |
| 29 | +"""An optional dictionary of configuration overrides for RepositoryProviderFactory instances. |
| 30 | +
|
| 31 | +This makes it possible to specify configuration values via environment variables rather than as |
| 32 | +class constructor parameters, allowing for easier secret setting. |
| 33 | +""" |
| 34 | + |
| 35 | +VCS_RELEASE_CLASS = "invenio_vcs.service:VCSRelease" |
| 36 | +"""VCSRelease class to be used for release handling.""" |
| 37 | + |
| 38 | +VCS_TEMPLATE_INDEX = "invenio_vcs/settings/index.html" |
| 39 | +"""Repositories list template.""" |
| 40 | + |
| 41 | +VCS_TEMPLATE_VIEW = "invenio_vcs/settings/view.html" |
| 42 | +"""Repository detail view template.""" |
| 43 | + |
| 44 | +VCS_ERROR_HANDLERS = None |
| 45 | +"""Definition of the way specific exceptions are handled.""" |
| 46 | + |
| 47 | +VCS_MAX_CONTRIBUTORS_NUMBER = 30 |
| 48 | +"""Max number of contributors of a release to be retrieved from vcs.""" |
| 49 | + |
| 50 | +VCS_CITATION_FILE = None |
| 51 | +"""Citation file name.""" |
| 52 | + |
| 53 | +VCS_CITATION_METADATA_SCHEMA = None |
| 54 | +"""Citation metadata schema.""" |
| 55 | + |
| 56 | +VCS_ZIPBALL_TIMEOUT = 300 |
| 57 | +"""Timeout for the zipball download, in seconds.""" |
| 58 | + |
| 59 | + |
| 60 | +def get_provider_list(app=current_app) -> list["RepositoryServiceProviderFactory"]: |
| 61 | + """Get a list of configured VCS provider factories.""" |
| 62 | + return app.config["VCS_PROVIDERS"] |
| 63 | + |
| 64 | + |
| 65 | +def get_provider_by_id(id: str) -> "RepositoryServiceProviderFactory": |
| 66 | + """Get a specific VCS provider by its registered ID.""" |
| 67 | + providers = get_provider_list() |
| 68 | + for provider in providers: |
| 69 | + if id == provider.id: |
| 70 | + return provider |
| 71 | + raise Exception(f"VCS provider with ID {id} not registered") |
| 72 | + |
| 73 | + |
| 74 | +def get_provider_config_override(id: str, app=current_app) -> dict: |
| 75 | + """Get the config override dict for a provider by ID, or an empty dictionary by default.""" |
| 76 | + return app.config["VCS_PROVIDER_CONFIG_DICT"].get(id, {}) |
0 commit comments