Commit 89b0d210 authored by Alexander Lercher's avatar Alexander Lercher

Final Fix?

parent 13dd065e
...@@ -2,8 +2,7 @@ FROM python:3 ...@@ -2,8 +2,7 @@ FROM python:3
LABEL maintainer="Manuel Herold" LABEL maintainer="Manuel Herold"
RUN apt-get update RUN apt-get update
RUN pip install flask RUN pip install -U pip
RUN pip install connexion[swagger-ui]
EXPOSE 5000 EXPOSE 5000
...@@ -12,9 +11,8 @@ WORKDIR /app ...@@ -12,9 +11,8 @@ WORKDIR /app
COPY src/data-hub/reputation-calculation-microservice/app/requirements.txt /app/ COPY src/data-hub/reputation-calculation-microservice/app/requirements.txt /app/
RUN pip install -r requirements.txt RUN pip install -r requirements.txt
COPY src/data-hub/reputation-calculation-microservice/app/ /app/
COPY src/modules/ /app/ COPY src/modules/ /app/
COPY src/data-hub/reputation-calculation-microservice/app/ /app/
RUN chmod a+x main.py RUN chmod a+x main.py
CMD ["python", "./main.py"] CMD ["python", "./main.py"]
\ No newline at end of file
...@@ -16,7 +16,8 @@ LOGGER = logging.getLogger(__name__) ...@@ -16,7 +16,8 @@ LOGGER = logging.getLogger(__name__)
############################# #############################
import connexion import connexion
from security import swagger_util from security import swagger_util
from env_info import is_running_locally, get_resources_path from pathlib import Path
import env_info
from flask import request from flask import request
from flask import redirect from flask import redirect
...@@ -26,29 +27,27 @@ from flask_cors import CORS ...@@ -26,29 +27,27 @@ from flask_cors import CORS
app = connexion.App(__name__, specification_dir='configs/') app = connexion.App(__name__, specification_dir='configs/')
CORS(app.app) CORS(app.app)
@app.app.before_request
def before_request():
if request.url.startswith('http://'):
url = request.url.replace('http://', 'https://', 1)
code = 301
return redirect(url, code=code)
@app.route('/', methods=['GET']) @app.route('/', methods=['GET'])
def api_root(): def api_root():
return redirect('/api/ui') return redirect('/api/ui')
# SSL configuration if not env_info.is_running_locally():
certificate_path = get_resources_path() swagger_path = "configs/swagger.yml"
context = (os.path.normpath(f'{certificate_path}/articonf1.crt'), os.path.normpath(f'{certificate_path}/articonf1.key')) # certificate and key files
if is_running_locally(): # SSL configuration
print("Running locally...") certificate_path = env_info.get_resources_path()
app.add_api(swagger_util.get_bundled_specs(Path("configs/swagger_local.yml")), context = (os.path.normpath(f'{certificate_path}/articonf1.crt'), os.path.normpath(f'{certificate_path}/articonf1.key')) # certificate and key files
resolver = connexion.RestyResolver("cms_rest_api"))
else: else:
app.add_api(swagger_util.get_bundled_specs(Path("configs/swagger.yml")), print("Running locally...")
swagger_path = "configs/swagger_local.yml"
context = None
app.add_api(swagger_util.get_bundled_specs(Path(swagger_path)),
resolver = connexion.RestyResolver("cms_rest_api")) resolver = connexion.RestyResolver("cms_rest_api"))
# start app # start app
if __name__ == '__main__': if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000, debug=True, use_reloader=False, ssl_context=context) # disable reloader so only subscribed once to rabbitmq app.run(host='0.0.0.0', port=5000, ssl_context=context)#, debug=True)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment