Revize 61535019
Přidáno uživatelem Stanislav Král před asi 4 roky(ů)
app.py | ||
---|---|---|
9 | 9 |
from src.controllers.certificates_controller import CertController |
10 | 10 |
from src.services.cryptography import CryptographyService, CryptographyException |
11 | 11 |
|
12 |
|
|
13 |
class X509ManagementApp(Flask): |
|
14 |
|
|
15 |
def run(self, host=None, port=None, debug=None, load_dotenv=True, **options): |
|
16 |
with self.app_context(): |
|
17 |
if not initialize_app(): |
|
18 |
return |
|
19 |
super(X509ManagementApp, self).run(host=host, port=port, debug=debug, load_dotenv=load_dotenv, **options) |
|
20 |
|
|
21 |
|
|
22 |
app = X509ManagementApp(__name__) |
|
12 |
app = Flask(__name__) |
|
23 | 13 |
|
24 | 14 |
|
25 | 15 |
@app.route('/') |
... | ... | |
58 | 48 |
return certificate_controller.get_certificate_trust_chain_by_id(id) |
59 | 49 |
|
60 | 50 |
|
61 |
def initialize_app() -> bool: |
|
51 |
def initialize_app(application) -> bool:
|
|
62 | 52 |
""" |
63 | 53 |
Initializes the application |
64 | 54 |
- configure dependency injection |
65 | 55 |
- check whether OpenSSL is on the system |
66 |
:return: boolean flag indicating whether initialization was successfull or not |
|
56 |
:param application Flask Application to be initialized. |
|
57 |
:return: boolean flag indicating whether initialization was successful or not |
|
67 | 58 |
""" |
68 | 59 |
|
69 | 60 |
modules = [configuration.configure_env_variable, ConnectionProvider] |
70 | 61 |
injector = Injector(modules) |
71 |
FlaskInjector(app=app, modules=modules) |
|
62 |
FlaskInjector(app=application, modules=modules)
|
|
72 | 63 |
|
73 | 64 |
# There's a little dependency on the CryptoService, which is not a pretty thing from |
74 | 65 |
# architectural point of view. However it is only a minimal piece of code and |
... | ... | |
86 | 77 |
return False |
87 | 78 |
|
88 | 79 |
|
80 |
# app initialization must follow endpoint declaration (after all Flask decoration) |
|
81 |
with app.app_context(): |
|
82 |
if not initialize_app(app): |
|
83 |
# TODO log this |
|
84 |
print("Failed to initialize app, aborting...") |
|
85 |
exit(-1) |
|
86 |
|
|
89 | 87 |
if __name__ == '__main__': |
90 | 88 |
app_host = "0.0.0.0" |
91 | 89 |
app_port = 5000 |
Také k dispozici: Unified diff
Renamed X509ManagementApp class and fixed application initialization when ran with gunicorn