This commit is contained in:
parent
db72904b62
commit
453b686cbe
10
.gitignore
vendored
10
.gitignore
vendored
@ -131,3 +131,13 @@ dmypy.json
|
|||||||
#Pycharm
|
#Pycharm
|
||||||
.idea/
|
.idea/
|
||||||
*.iml
|
*.iml
|
||||||
|
|
||||||
|
# Wing project file
|
||||||
|
*.wpr
|
||||||
|
|
||||||
|
# Nano, vi, vim lockfile
|
||||||
|
*.swp
|
||||||
|
|
||||||
|
# log
|
||||||
|
*.log
|
||||||
|
|
||||||
|
26
Dockerfile
26
Dockerfile
@ -1,28 +1,14 @@
|
|||||||
# Use the official lightweight Python image.
|
|
||||||
# https://hub.docker.com/_/python
|
|
||||||
FROM python:3.8-slim
|
FROM python:3.8-slim
|
||||||
|
|
||||||
# Copy local code to the container image.
|
ADD storage_service requirements.txt /storage_service/
|
||||||
ENV APP_HOME /app
|
WORKDIR /storage_service/
|
||||||
ENV PIP_NO_CACHE_DIR=true
|
|
||||||
|
|
||||||
# Set timezone
|
ENV PIP_NO_CACHE_DIR=true
|
||||||
ENV TZ Europe/Budapest
|
ENV TZ Europe/Budapest
|
||||||
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
|
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
|
||||||
|
|
||||||
WORKDIR $APP_HOME
|
RUN pip3 install -r requirements.txt
|
||||||
|
|
||||||
ARG RELEASE_ID
|
EXPOSE 8000
|
||||||
ENV RELEASE_ID ${RELEASE_ID:-""}
|
CMD ["gunicorn", "-b", "0.0.0.0:8000", "app:app"]
|
||||||
|
|
||||||
#Copy requirements to install
|
|
||||||
COPY requirements.txt ./
|
|
||||||
|
|
||||||
# Install production dependencies.
|
|
||||||
RUN pip install -r requirements.txt
|
|
||||||
|
|
||||||
COPY ./src ./src
|
|
||||||
|
|
||||||
EXPOSE 8080
|
|
||||||
|
|
||||||
ENTRYPOINT ["gunicorn", "-b", "0.0.0.0:8080", "--workers", "1", "--threads", "8", "app:app"]
|
|
||||||
|
1
requirements-dev.txt
Normal file
1
requirements-dev.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
pytest
|
@ -1,2 +1,8 @@
|
|||||||
sentry_sdk
|
requests
|
||||||
|
blinker
|
||||||
|
Flask
|
||||||
|
marshmallow
|
||||||
|
Flask-Classful
|
||||||
gunicorn
|
gunicorn
|
||||||
|
sentry_sdk
|
||||||
|
flask_minio
|
31
storage_service/app.py
Normal file
31
storage_service/app.py
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
import os
|
||||||
|
from flask import Flask
|
||||||
|
from werkzeug.middleware.proxy_fix import ProxyFix
|
||||||
|
|
||||||
|
# import stuff
|
||||||
|
from utils import register_all_error_handlers
|
||||||
|
|
||||||
|
# import views
|
||||||
|
from views import ObjectView
|
||||||
|
|
||||||
|
# create flask app
|
||||||
|
app = Flask(__name__)
|
||||||
|
app.wsgi_app = ProxyFix(app.wsgi_app, x_proto=1)
|
||||||
|
|
||||||
|
# important stuff
|
||||||
|
app.secret_key = os.environ.get('SECRET_KEY', os.urandom(12))
|
||||||
|
|
||||||
|
# register error handlers
|
||||||
|
register_all_error_handlers(app)
|
||||||
|
|
||||||
|
# register views
|
||||||
|
for view in [ObjectView]:
|
||||||
|
view.register(app, trailing_slash=False)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# start debuggig if needed
|
||||||
|
if __name__ == "__main__":
|
||||||
|
app.run(debug=True)
|
1
storage_service/schemas/__init__.py
Normal file
1
storage_service/schemas/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
#!/usr/bin/env python3
|
1
storage_service/tests/__init__.py
Normal file
1
storage_service/tests/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
import os
|
3
storage_service/utils/__init__.py
Normal file
3
storage_service/utils/__init__.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
from .require_decorators import json_required
|
||||||
|
from .error_handlers import register_all_error_handlers
|
21
storage_service/utils/error_handlers.py
Normal file
21
storage_service/utils/error_handlers.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
|
||||||
|
def get_standard_error_handler(code: int):
|
||||||
|
|
||||||
|
def error_handler(err):
|
||||||
|
return {"msg": str(err)}, code
|
||||||
|
|
||||||
|
return error_handler
|
||||||
|
|
||||||
|
|
||||||
|
def register_all_error_handlers(app):
|
||||||
|
"""
|
||||||
|
function to register all handlers
|
||||||
|
"""
|
||||||
|
|
||||||
|
error_codes_to_override = [404, 403, 401, 405, 400, 409, 422]
|
||||||
|
|
||||||
|
for code in error_codes_to_override:
|
||||||
|
app.register_error_handler(code, get_standard_error_handler(code))
|
||||||
|
|
19
storage_service/utils/require_decorators.py
Normal file
19
storage_service/utils/require_decorators.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
from flask import request, current_app, abort
|
||||||
|
|
||||||
|
from functools import wraps
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def json_required(f):
|
||||||
|
|
||||||
|
@wraps(f)
|
||||||
|
def call(*args, **kwargs):
|
||||||
|
|
||||||
|
if request.is_json:
|
||||||
|
return f(*args, **kwargs)
|
||||||
|
else:
|
||||||
|
abort(400, "JSON required")
|
||||||
|
|
||||||
|
return call
|
||||||
|
|
2
storage_service/views/__init__.py
Normal file
2
storage_service/views/__init__.py
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
from .object_view import ObjectView
|
9
storage_service/views/object_view.py
Normal file
9
storage_service/views/object_view.py
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
from flask import jsonify
|
||||||
|
from flask_classful import FlaskView
|
||||||
|
|
||||||
|
|
||||||
|
class ObjectView(FlaskView):
|
||||||
|
|
||||||
|
def post(self):
|
||||||
|
return jsonify({}), 200
|
Loading…
Reference in New Issue
Block a user