Projekt

Obecné

Profil

« Předchozí | Další » 

Revize a766e644

Přidáno uživatelem Jan Pašek před asi 4 roky(ů)

Re #8571 - Added necessary configuration

Zobrazit rozdíly:

src/config/configuration.py
3 3
import configparser
4 4
from injector import singleton
5 5

  
6
from src.constants import DEFAULT_CONNECTION_STRING, TEST_DATABASE_FILE
6
from src.constants import DEFAULT_CONNECTION_STRING, TEST_DATABASE_FILE, DEFAULT_SERVER_BASE_URL
7 7

  
8 8
DATABASE_SECTION = "Database"
9 9
DATABASE_CONNECTION_STRING = "ConnectionString"
10 10

  
11
SERVER_SECTION = "Server"
12
SERVER_BASE_URL = "ServerBaseURL"
13

  
11 14

  
12 15
class Configuration:
13 16
    """
......
21 24
        It must initialize all variables to their default values
22 25
        """
23 26
        self.connection_string = DEFAULT_CONNECTION_STRING
27
        self.base_server_url = DEFAULT_SERVER_BASE_URL
24 28

  
25 29

  
26 30
def test_configuration():
......
44 48
    config_file = os.environ.get("X509_CONFIG")
45 49
    app_configuration = Configuration()
46 50
    # if configuration file is not specified use the default configuration
47
    if config_file is not None:
51
    if config_file is not None and os.path.exists(config_file):
48 52
        config = configparser.ConfigParser()
49 53
        config.read(config_file)
50 54

  
......
52 56
            database_config = config[DATABASE_SECTION]
53 57
            app_configuration.connection_string = database_config.get(DATABASE_CONNECTION_STRING,
54 58
                                                                      DEFAULT_CONNECTION_STRING)
59
        if config[SERVER_SECTION] is not None:
60
            server_config = config[SERVER_SECTION]
61
            app_configuration.base_server_url = server_config.get(SERVER_BASE_URL,
62
                                                                  DEFAULT_SERVER_BASE_URL)
55 63

  
56 64
    binder.bind(Configuration, to=app_configuration, scope=singleton)

Také k dispozici: Unified diff