some more preparational work done

This commit is contained in:
Daniel Schick 2023-03-23 17:11:42 +01:00
parent 1bca77bf12
commit d4cad33513
4 changed files with 52 additions and 21 deletions

View File

@ -13,9 +13,11 @@ from .api import participant
from .api import times from .api import times
from .api import notifications from .api import notifications
from .api import berths from .api import berths
from .impl import util
def create_app(test_config=None): def create_app(test_config=None):
global connection_pool
app = Flask(__name__, instance_relative_config=True) app = Flask(__name__, instance_relative_config=True)
app.config.from_mapping( app.config.from_mapping(
SECRET_KEY='dev' SECRET_KEY='dev'
@ -42,14 +44,26 @@ def create_app(test_config=None):
logging.basicConfig(filename='brecal.log', level=logging.DEBUG, format='%(asctime)s | %(name)s | %(levelname)s | %(message)s') logging.basicConfig(filename='brecal.log', level=logging.DEBUG, format='%(asctime)s | %(name)s | %(levelname)s | %(message)s')
logging.info('App started') logging.info('App started')
conn_from_pool = mysql.connector.connect( try:
pool_name="brecal_pool", pool_size=10, port=3306, user="ds", password="HalloWach23", database="bremen_calling" connection_pool = mysql.connector.connect(
) host="lager",
port=3306,
user="ds",
password="HalloWach23",
pool_name="brecal_pool",
pool_size=20,
database="bremen_calling"
)
# test connection commands = pydapper.using(connection_pool)
commands = pydapper.using(conn_from_pool) data = commands.query_single("SELECT id from `user`")
data = commands.query_single("SELECT id from `user`") print(data)
print(data)
except mysql.connector.PoolError as e:
logging.error(f"Failed to create connection pool: {e}")
print(e)
sessions = dict()
return app return app

View File

@ -9,5 +9,5 @@ bp = Blueprint('verify', __name__)
@bp.route('/verify', methods=['get']) @bp.route('/verify', methods=['get'])
def GetVerify(): def GetVerify():
apikey = request.headers.get('X-Api-Key')
return impl.verify.GetVerify() return impl.verify.GetVerify(apikey)

View File

@ -1,22 +1,30 @@
import json import json
import logging import logging
import pydapper import pydapper
import mysql.connector
from ..schemas import model
from ..schemas import __init__
def GetVerify(options): def GetVerify(apikey):
""" """
:param apikey: the api-key registered with the user
"""
""" if not apikey
print(options) return json.dumps("missing api key"), 400
sentinel = object()
# 'mysql+pymysql://' + username + ':' + password + '@' + server + database
# with connect("mysql+mysql://root:pydapper@localhost:3307/pydapper", autocommit=True) as commands:
# data = commands.query_single_or_default("SELECT id from `user` WHERE api_key=?", )
# Implement your business logic here
# All the parameters are present in the options argument
return json.dumps("<integer>"), 200 sentinel = object()
try:
commands = pydapper.using(__init__.connection_pool)
data = commands.query_single_or_default("SELECT id from `user` WHERE api_key=?api_key?", default=sentinel, model=model.User, param={"api_key" : apikey})
if(data is sentinel):
return json.dumps("wrong api key", 403)
except Exception as ex:
return json.dumps("logon failed"), 500
logging.error(e)
return json.dumps("<integer>"), 200

View File

@ -77,3 +77,12 @@ class Shipcalls(Shipcall):
class TimesList(Times): class TimesList(Times):
pass pass
class User(Schema):
id = fields.Int()
participant_id = fields.Int()
first_name = fields.String()
last_name = fields.String()
user_name = fields.String()
password_hash = fields.String()
api_key = fields.String()