minor redis adjustments
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Torma Kristóf 2020-11-28 20:17:17 +01:00
parent 791003f89e
commit 73c1636063
7 changed files with 38 additions and 2 deletions

View File

@ -7,12 +7,13 @@ from flask_restful import Api
from flask_cors import CORS from flask_cors import CORS
import sentry_sdk import sentry_sdk
from sentry_sdk.integrations.flask import FlaskIntegration from sentry_sdk.integrations.flask import FlaskIntegration
from sentry_sdk.integrations.redis import RedisIntegration
from healthcheck import HealthCheck from healthcheck import HealthCheck
from flaskaddons.marshm import ma from flaskaddons.marshm import ma
from flaskaddons.fred import flaskred from flaskaddons.fred import flaskred
from utils.config import SENTRY_DSN, RELEASEMODE, RELEASE_ID, PORT, DEBUG, REDIS_URL, ALLOWED_ORIGINS from utils.config import SENTRY_DSN, RELEASEMODE, RELEASE_ID, PORT, DEBUG, REDIS_URL, ALLOWED_ORIGINS
from utils.errorhandlers import register_all_error_handlers from utils import register_all_error_handlers, redis_available
from resources import LoginApi, ListsApi, MeApi, SingleListApi, ItemApi from resources import LoginApi, ListsApi, MeApi, SingleListApi, ItemApi
""" """
@ -27,7 +28,7 @@ __version__text__ = "1"
if SENTRY_DSN: if SENTRY_DSN:
sentry_sdk.init( sentry_sdk.init(
dsn=SENTRY_DSN, dsn=SENTRY_DSN,
integrations=[FlaskIntegration()], integrations=[FlaskIntegration(), RedisIntegration()],
traces_sample_rate=1.0, traces_sample_rate=1.0,
send_default_pii=True, send_default_pii=True,
release=RELEASE_ID, release=RELEASE_ID,
@ -70,6 +71,7 @@ api.add_resource(ListsApi, '/api/lists')
api.add_resource(SingleListApi, '/api/lists/<listid>') api.add_resource(SingleListApi, '/api/lists/<listid>')
api.add_resource(ItemApi, '/api/items/<itemid>') api.add_resource(ItemApi, '/api/items/<itemid>')
health.add_check(redis_available)
app.add_url_rule("/healthz", "healthcheck", view_func=lambda: health.run()) app.add_url_rule("/healthz", "healthcheck", view_func=lambda: health.run())
register_all_error_handlers(app) register_all_error_handlers(app)

View File

@ -7,6 +7,8 @@ __copyright__ = "Copyright 2020, onSpot Team"
__module_name__ = "itemapi" __module_name__ = "itemapi"
__version__text__ = "1" __version__text__ = "1"
from datetime import timedelta
from flask import request, current_app, abort from flask import request, current_app, abort
from flaskaddons.fred import flaskred from flaskaddons.fred import flaskred
@ -24,6 +26,8 @@ class ItemApi(APIInteractionResource):
except Exception as e: except Exception as e:
current_app.logger.info(e) current_app.logger.info(e)
abort(401, "unauthorized") abort(401, "unauthorized")
flaskred.expire(request.headers.get('Authorization'), timedelta(minutes=15))
try: try:
itemtype = flaskred.get(itemid).decode('UTF-8') itemtype = flaskred.get(itemid).decode('UTF-8')
except Exception as e: except Exception as e:

View File

@ -7,6 +7,8 @@ __copyright__ = "Copyright 2020, onSpot Team"
__module_name__ = "listsapi" __module_name__ = "listsapi"
__version__text__ = "1" __version__text__ = "1"
from datetime import timedelta
import musicbrainzngs import musicbrainzngs
from flask import current_app, abort, request from flask import current_app, abort, request
@ -26,6 +28,8 @@ class ListsApi(UserStoreResource):
current_app.logger.info(e) current_app.logger.info(e)
abort(401, "unauthorized") abort(401, "unauthorized")
flaskred.expire(request.headers.get('Authorization'), timedelta(minutes=15))
musicbrainzngs.auth(currcreds['name'], currcreds['password']) musicbrainzngs.auth(currcreds['name'], currcreds['password'])
collections = musicbrainzngs.get_collections() collections = musicbrainzngs.get_collections()
musicbrainzngs.auth(None, None) musicbrainzngs.auth(None, None)

View File

@ -7,6 +7,8 @@ __copyright__ = "Copyright 2020, onSpot Team"
__module_name__ = "meapi" __module_name__ = "meapi"
__version__text__ = "1" __version__text__ = "1"
from datetime import timedelta
from flask import request, current_app, abort from flask import request, current_app, abort
from flask_restful import Resource from flask_restful import Resource
@ -24,4 +26,5 @@ class MeApi(Resource):
except Exception as e: except Exception as e:
current_app.logger.info(e) current_app.logger.info(e)
abort(401, "unauthorized") abort(401, "unauthorized")
flaskred.expire(request.headers.get('Authorization'), timedelta(minutes=15))
return {"name": currusername}, 200 return {"name": currusername}, 200

View File

@ -7,6 +7,8 @@ __copyright__ = "Copyright 2020, onSpot Team"
__module_name__ = "singlelistapi" __module_name__ = "singlelistapi"
__version__text__ = "1" __version__text__ = "1"
from datetime import timedelta
import musicbrainzngs import musicbrainzngs
from flask import request, current_app, abort from flask import request, current_app, abort
@ -25,6 +27,7 @@ class SingleListApi(APIInteractionResource):
except Exception as e: except Exception as e:
current_app.logger.info(e) current_app.logger.info(e)
abort(401, "unauthorized") abort(401, "unauthorized")
flaskred.expire(request.headers.get('Authorization'), timedelta(minutes=15))
try: try:
list_type = flaskred.get(listid).decode('UTF-8') list_type = flaskred.get(listid).decode('UTF-8')
except Exception as e: except Exception as e:

View File

@ -1 +1,3 @@
from .aes_encrypt import AESCrypto from .aes_encrypt import AESCrypto
from .healthchecks import redis_available
from .errorhandlers import register_all_error_handlers

18
src/utils/healthchecks.py Normal file
View File

@ -0,0 +1,18 @@
#!/usr/bin/env python3
from flaskaddons import flaskred
"""
Healthchek functions
"""
__author__ = "@tormakris"
__copyright__ = "Copyright 2020, onSpot Team"
__module_name__ = "healthchecks"
__version__text__ = "1"
def redis_available():
flaskred.info()
return True, "redis ok"