michael cors
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Torma Kristóf 2020-11-26 02:20:16 +01:00
parent 025e380e6f
commit 4fa6951c8a
4 changed files with 17 additions and 6 deletions

View File

@ -9,3 +9,4 @@ marshmallow
flask-marshmallow flask-marshmallow
spotipy spotipy
pycryptodome pycryptodome
flask-cors

View File

@ -1,15 +1,17 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import logging import logging
import musicbrainzngs
from flask import Flask from flask import Flask
from flask_restful import Api from flask_restful import Api
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 healthcheck import HealthCheck from healthcheck import HealthCheck
from marshm import ma from marshm import ma
from fred import flaskred from fred import flaskred
from config import SENTRY_DSN, RELEASEMODE, RELEASE_ID, PORT, DEBUG, REDIS_URL from config import SENTRY_DSN, RELEASEMODE, RELEASE_ID, PORT, DEBUG, REDIS_URL, ALLOWED_ORIGINS
from errorhandlers import register_all_error_handlers from errorhandlers import register_all_error_handlers
from resources import LoginApi, ListsApi, MeApi, SingleListApi, TrackApi from resources import LoginApi, ListsApi, MeApi, SingleListApi, TrackApi
@ -41,11 +43,20 @@ api = Api(app)
health = HealthCheck() health = HealthCheck()
ma.init_app(app) ma.init_app(app)
flaskred.init_app(app) flaskred.init_app(app)
CORS(app, origins=ALLOWED_ORIGINS)
formatter = logging.Formatter( formatter = logging.Formatter(
fmt="%(asctime)s - %(levelname)s - %(module)s - %(message)s" fmt="%(asctime)s - %(levelname)s - %(module)s - %(message)s"
) )
@app.before_first_request
def before_first_request():
musicbrainzngs.set_useragent("onSpot", 1)
musicbrainzngs.set_rate_limit(1.0, 20)
musicbrainzngs.https = True
handler = logging.StreamHandler() handler = logging.StreamHandler()
handler.setFormatter(formatter) handler.setFormatter(formatter)

View File

@ -14,6 +14,7 @@ __version__text__ = "1"
PORT = os.environ.get("ONSPOT_PORT", 8080) PORT = os.environ.get("ONSPOT_PORT", 8080)
DEBUG = os.environ.get("ONSPOT_DEBUG", True) DEBUG = os.environ.get("ONSPOT_DEBUG", True)
ALLOWED_ORIGINS = os.environ.get('ALLOWED_ORIGINS', '*')
SENTRY_DSN = os.environ.get("SENTRY_DSN") SENTRY_DSN = os.environ.get("SENTRY_DSN")
RELEASE_ID = os.environ.get("RELEASE_ID", "test") RELEASE_ID = os.environ.get("RELEASE_ID", "test")

View File

@ -41,10 +41,8 @@ class LoginApi(Resource):
try: try:
musicbrainzngs.auth(userobj['name'], userobj['password']) musicbrainzngs.auth(userobj['name'], userobj['password'])
musicbrainzngs.set_useragent("onSpot", 1) musicbrainzngs.get_collections()
musicbrainzngs.set_rate_limit(1.0, 20) musicbrainzngs.auth(None, None)
musicbrainzngs.https = True
print(musicbrainzngs.get_collections())
except Exception as e: except Exception as e:
current_app.logger.warning(e) current_app.logger.warning(e)
abort(401, "login denied to musicbrainz") abort(401, "login denied to musicbrainz")