Revize 81dbb479
Přidáno uživatelem Jan Pašek před asi 4 roky(ů)
app.py | ||
---|---|---|
6 | 6 |
from src.config import configuration |
7 | 7 |
from src.config.connection_provider import ConnectionProvider |
8 | 8 |
from src.controllers.certificates_controller import CertController |
9 |
from src.services.cryptography import CryptographyService, CryptographyException |
|
9 | 10 |
|
10 | 11 |
|
11 | 12 |
class X509ManagementApp(Flask): |
12 | 13 |
|
13 | 14 |
def run(self, host=None, port=None, debug=None, load_dotenv=True, **options): |
14 | 15 |
with self.app_context(): |
15 |
initialize_app() |
|
16 |
if not initialize_app(): |
|
17 |
return |
|
16 | 18 |
super(X509ManagementApp, self).run(host=host, port=port, debug=debug, load_dotenv=load_dotenv, **options) |
17 | 19 |
|
18 | 20 |
|
... | ... | |
55 | 57 |
return certificate_controller.get_certificate_trust_chain_by_id(id) |
56 | 58 |
|
57 | 59 |
|
58 |
def initialize_app(): |
|
60 |
def initialize_app() -> bool: |
|
61 |
""" |
|
62 |
Initializes the application |
|
63 |
- configure dependency injection |
|
64 |
- check whether OpenSSL is on the system |
|
65 |
:return: boolean flag indicating whether initialization was successfull or not |
|
66 |
""" |
|
59 | 67 |
global certificate_controller |
60 | 68 |
|
61 | 69 |
injector = Injector([configuration.configure_default, ConnectionProvider]) |
62 | 70 |
certificate_controller = injector.get(CertController) |
63 | 71 |
|
72 |
# There's a little dependency on the CryptoService, which is not a pretty thing from |
|
73 |
# architectural point of view. However it is only a minimal piece of code and |
|
74 |
# it makes sense to do it in this way instead of trying to run openssl via subprocess here |
|
75 |
cryptography_service = injector.get(CryptographyService) |
|
76 |
try: |
|
77 |
# if version string is returned, OpenSSL is present on the system |
|
78 |
print(f"Using {cryptography_service.get_openssl_version()}") |
|
79 |
# TODO log the version instead of prining it out |
|
80 |
return True |
|
81 |
except CryptographyException: |
|
82 |
# If getting the version string throws an exception the OpenSSL is not available |
|
83 |
print("OpenSSL was not located on the system. Application will now exit.") |
|
84 |
# TODO add logging here |
|
85 |
return False |
|
86 |
|
|
64 | 87 |
|
65 | 88 |
if __name__ == '__main__': |
66 | 89 |
app_host = "0.0.0.0" |
Také k dispozici: Unified diff
Re #8569 Checking presence of OpenSSL during init