linting
This commit is contained in:
parent
2ba341ae7f
commit
a23d797f90
@ -14,6 +14,7 @@ spotframework_logger = logging.getLogger('spotframework')
|
||||
fmframework_logger = logging.getLogger('fmframework')
|
||||
spotfm_logger = logging.getLogger('spotfm')
|
||||
|
||||
|
||||
def init_log(cloud=False, console=False):
|
||||
if cloud:
|
||||
import google.cloud.logging
|
||||
@ -44,5 +45,6 @@ def init_log(cloud=False, console=False):
|
||||
fmframework_logger.addHandler(stream_handler)
|
||||
spotfm_logger.addHandler(stream_handler)
|
||||
|
||||
|
||||
if os.environ.get('DEPLOY_DESTINATION', None) == 'PROD':
|
||||
init_log(cloud=True)
|
||||
init_log(cloud=True)
|
||||
|
@ -78,6 +78,7 @@ def login_or_jwt(func):
|
||||
|
||||
return login_or_jwt_wrapper
|
||||
|
||||
|
||||
def jwt_required(func):
|
||||
@functools.wraps(func)
|
||||
def jwt_required_wrapper(*args, **kwargs):
|
||||
|
@ -113,9 +113,9 @@ def jwt_token():
|
||||
else:
|
||||
expiry = config.jwt_default_length
|
||||
|
||||
token = generate_key(user, timeout=timedelta(seconds=expiry))
|
||||
generated_token = generate_key(user, timeout=timedelta(seconds=expiry))
|
||||
|
||||
return jsonify({"token": token, "status": "success"}), 200
|
||||
return jsonify({"token": generated_token, "status": "success"}), 200
|
||||
else:
|
||||
logger.warning(f'failed token attempt {username}')
|
||||
return jsonify({"message": 'authentication failed', "status": "error"}), 401
|
||||
@ -140,7 +140,7 @@ def register():
|
||||
|
||||
if username is None or password is None or password_again is None:
|
||||
|
||||
if (request_json := request.get_json()) != None:
|
||||
if (request_json := request.get_json()) is not None:
|
||||
username = request_json.get('username', None)
|
||||
password = request_json.get('password', None)
|
||||
password_again = request_json.get('password_again', None)
|
||||
|
@ -1,9 +1,9 @@
|
||||
from ctypes import Union
|
||||
from datetime import timedelta, datetime, timezone
|
||||
import jwt
|
||||
from music.model.user import User
|
||||
from music.model.config import Config
|
||||
|
||||
|
||||
def get_jwt_secret_key() -> str:
|
||||
|
||||
config = Config.collection.get("config/music-tools")
|
||||
@ -13,6 +13,7 @@ def get_jwt_secret_key() -> str:
|
||||
|
||||
return config.jwt_secret_key
|
||||
|
||||
|
||||
def generate_key(user: User, timeout: datetime | timedelta = timedelta(minutes=60)) -> str:
|
||||
|
||||
if isinstance(timeout, timedelta):
|
||||
@ -28,6 +29,7 @@ def generate_key(user: User, timeout: datetime | timedelta = timedelta(minutes=6
|
||||
|
||||
return jwt.encode(payload, get_jwt_secret_key(), algorithm="HS512")
|
||||
|
||||
|
||||
def validate_key(key: str) -> dict:
|
||||
|
||||
try:
|
||||
@ -37,5 +39,5 @@ def validate_key(key: str) -> dict:
|
||||
|
||||
return decoded
|
||||
|
||||
except Exception as e:
|
||||
except jwt.exceptions.PyJWTError as e:
|
||||
pass
|
||||
|
@ -1,5 +1,5 @@
|
||||
from fireo.models import Model
|
||||
from fireo.fields import TextField, BooleanField, DateTime, NumberField, ListField
|
||||
from fireo.fields import TextField, NumberField
|
||||
|
||||
|
||||
class Config(Model):
|
||||
|
Loading…
Reference in New Issue
Block a user