Revize a766e644
Přidáno uživatelem Jan Pašek před asi 4 roky(ů)
docker-compose.yml | ||
---|---|---|
20 | 20 |
dockerfile: docker/gunicorn/Dockerfile |
21 | 21 |
networks: |
22 | 22 |
- web |
23 |
environment: |
|
24 |
- X509_CONFIG=test_server.cfg |
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) |
src/constants.py | ||
---|---|---|
51 | 51 |
|
52 | 52 |
# configuration default |
53 | 53 |
DEFAULT_CONNECTION_STRING = "db/database_sqlite.db" |
54 |
DEFAULT_SERVER_BASE_URL = "http://localhost" |
|
55 |
|
|
56 |
# available certificate states and revocation reasons |
|
57 |
CERTIFICATE_STATES = {"valid", "revoked"} |
|
58 |
CERTIFICATE_REVOCATION_REASONS = {"unspecified", "keyCompromise", |
|
59 |
"cACompromise", "affiliationChanged", |
|
60 |
"superseded", "cessationOfOperation", |
|
61 |
"certificateHold", "removeFromCRL", |
|
62 |
"privilegeWithdrawn", "aACompromise"} |
test_server.cfg | ||
---|---|---|
1 |
[Database] |
|
2 |
ConnectionString=db/database_sqlite.db |
|
3 |
|
|
4 |
[Server] |
|
5 |
SERVER_BASE_URL=http://78.128.250.101 |
Také k dispozici: Unified diff
Re #8571 - Added necessary configuration