0.3 #146

Merged
edraft merged 359 commits from 0.3 into master 2023-01-12 07:04:40 +01:00
17 changed files with 154 additions and 18 deletions
Showing only changes of commit 411e44a681 - Show all commits

View File

@ -1,8 +1,10 @@
import sys
from functools import partial
from blinker import Namespace
from cpl_core.dependency_injection import ServiceProviderABC
from flask import Flask, request
from flask_cors import CORS
from bot_api.configuration.api_settings import ApiSettings
from bot_api.logging.api_logger import ApiLogger
@ -27,20 +29,26 @@ class Api(Flask):
self._services = services
self._apt_settings = api_settings
self._cors = CORS(self, support_credentials=True)
# register before request
self.before_request_funcs.setdefault(None, []).append(self.before_request)
my_signals = Namespace()
notify = my_signals.signal('notify')
def _register_routes(self):
for path, f in Route.registered_routes.items():
route = f[0]
kwargs = f[1]
cls = None
qual_name_split = f.__qualname__.split('.')
qual_name_split = route.__qualname__.split('.')
if len(qual_name_split) > 0:
cls_type = vars(sys.modules[f.__module__])[qual_name_split[0]]
cls_type = vars(sys.modules[route.__module__])[qual_name_split[0]]
cls = self._services.get_service(cls_type)
partial_f = partial(f, self if cls is None else cls)
partial_f.__name__ = f.__name__
self.route(path)(partial_f)
partial_f = partial(route, self if cls is None else cls)
partial_f.__name__ = route.__name__
self.route(path, **kwargs)(partial_f)
def before_request(self, *args, **kwargs):
self._logger.debug(__name__, f'Received GET @{request.url}')

View File

@ -10,6 +10,7 @@ from flask import Flask
from bot_api.api import Api
from bot_api.api_thread import ApiThread
from bot_api.controller.api_controller import ApiController
from bot_api.controller.auth_controller import AuthController
from bot_core.abc.module_abc import ModuleABC
from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
@ -33,4 +34,5 @@ class ApiModule(ModuleABC):
services.add_singleton(ApiThread)
services.add_singleton(Flask, Api)
services.add_transient(AuthController)
services.add_transient(ApiController)

View File

@ -17,11 +17,14 @@
"LicenseDescription": "",
"Dependencies": [
"cpl-core==2022.10.0.post6",
"Flask==2.2.2",
"Flask[async]==2.2.2",
"Flask-Classful==0.14.2"
"Flask-Classful==0.14.2",
"Flask-Cors==3.0.10",
"PyJWT==2.5.0"
],
"DevDependencies": [
"cpl-cli>=2022.10.0"
"cpl-cli==2022.10.0"
],
"PythonVersion": ">=3.10.4",
"PythonPath": {

View File

@ -1 +1,26 @@
# -*- coding: utf-8 -*-
"""
bot Keksdose bot
~~~~~~~~~~~~~~~~~~~
Discord bot for the Keksdose discord Server
:copyright: (c) 2022 sh-edraft.de
:license: MIT, see LICENSE for more details.
"""
__title__ = 'bot_api.configuration'
__author__ = 'Sven Heidemann'
__license__ = 'MIT'
__copyright__ = 'Copyright (c) 2022 sh-edraft.de'
__version__ = '0.2.3'
from collections import namedtuple
# imports
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='0', minor='2', micro='3')

View File

@ -0,0 +1,47 @@
from cpl_core.configuration import ConfigurationABC
from cpl_core.environment import ApplicationEnvironmentABC
from cpl_core.mailing import EMailClientABC, EMailClientSettings
from cpl_query.extension import List
from cpl_translation import TranslatePipe
from flask import request
from flask_cors import cross_origin
from bot_api.api import Api
from bot_api.logging.api_logger import ApiLogger
from bot_api.model.token_dto import TokenDTO
from bot_api.route.route import Route
from bot_data.model.auth_user import AuthUser
class AuthController:
def __init__(
self,
config: ConfigurationABC,
env: ApplicationEnvironmentABC,
logger: ApiLogger,
t: TranslatePipe,
api: Api,
mail_settings: EMailClientSettings,
mailer: EMailClientABC
):
self._config = config
self._env = env
self._logger = logger
self._t = t
self._api = api
self._mail_settings = mail_settings
self._mailer = mailer
@Route.route('/api/auth/get-all-users')
async def get_all_users(self) -> List[AuthUser]:
pass
@Route.route('/api/auth/get-filtered-users', methods=['POST'])
async def get_filtered_users(self) -> List[AuthUser]:
pass
@Route.route('/api/auth/login', methods=['POST'])
async def login(self) -> dict:
self._logger.warn(__name__, f'Received {request.json}')
return TokenDTO().to_dict()

View File

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
"""
bot Keksdose bot
~~~~~~~~~~~~~~~~~~~
Discord bot for the Keksdose discord Server
:copyright: (c) 2022 sh-edraft.de
:license: MIT, see LICENSE for more details.
"""
__title__ = 'bot_api.filter'
__author__ = 'Sven Heidemann'
__license__ = 'MIT'
__copyright__ = 'Copyright (c) 2022 sh-edraft.de'
__version__ = '0.2.3'
from collections import namedtuple
# imports:
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='0', minor='2', micro='3')

View File

@ -2,10 +2,10 @@ class Route:
registered_routes = {}
@classmethod
def route(cls, path=None):
def route(cls, path=None, **kwargs):
# simple decorator for class based views
def inner(fn):
cls.registered_routes[path] = fn
cls.registered_routes[path] = (fn, kwargs)
return fn
return inner

View File

@ -1 +1,26 @@
# -*- coding: utf-8 -*-
"""
bot Keksdose bot
~~~~~~~~~~~~~~~~~~~
Discord bot for the Keksdose discord Server
:copyright: (c) 2022 sh-edraft.de
:license: MIT, see LICENSE for more details.
"""
__title__ = 'bot_api.service'
__author__ = 'Sven Heidemann'
__license__ = 'MIT'
__copyright__ = 'Copyright (c) 2022 sh-edraft.de'
__version__ = '0.2.3'
from collections import namedtuple
# imports
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='0', minor='2', micro='3')

View File

@ -19,7 +19,7 @@
"cpl-core>=2022.10.0"
],
"DevDependencies": [
"cpl-cli>=2022.10.0"
"cpl-cli==2022.10.0"
],
"PythonVersion": ">=3.10.4",
"PythonPath": {

View File

@ -19,7 +19,7 @@
"cpl-core>=2022.10.0"
],
"DevDependencies": [
"cpl-cli>=2022.10.0"
"cpl-cli==2022.10.0"
],
"PythonVersion": ">=3.10.4",
"PythonPath": {

View File

@ -19,7 +19,7 @@
"cpl-core>=2022.10.0.post5"
],
"DevDependencies": [
"cpl-cli>=2022.10.0"
"cpl-cli==2022.10.0"
],
"PythonVersion": ">=3.10.4",
"PythonPath": {

View File

@ -19,7 +19,7 @@
"cpl-core>=2022.10.0.post5"
],
"DevDependencies": [
"cpl-cli>=2022.10.0"
"cpl-cli==2022.10.0"
],
"PythonVersion": ">=3.10.4",
"PythonPath": {

View File

@ -19,7 +19,7 @@
"cpl-core>=2022.10.0.post2"
],
"DevDependencies": [
"cpl-cli>=2022.10.0"
"cpl-cli==2022.10.0"
],
"PythonVersion": ">=3.10.4",
"PythonPath": {

View File

@ -19,7 +19,7 @@
"cpl-core>=2022.10.0.post2"
],
"DevDependencies": [
"cpl-cli>=2022.10.0"
"cpl-cli==2022.10.0"
],
"PythonVersion": ">=3.10.4",
"PythonPath": {

View File

@ -19,7 +19,7 @@
"cpl-core>=2022.10.0.post2"
],
"DevDependencies": [
"cpl-cli>=2022.10.0"
"cpl-cli==2022.10.0"
],
"PythonVersion": ">=3.10.4",
"PythonPath": {

View File

@ -19,7 +19,7 @@
"cpl-core>=2022.10.0.post5"
],
"DevDependencies": [
"cpl-cli>=2022.10.0"
"cpl-cli==2022.10.0"
],
"PythonVersion": ">=3.10.4",
"PythonPath": {

View File

@ -19,7 +19,7 @@
"cpl-core>=2022.10.0.post2"
],
"DevDependencies": [
"cpl-cli>=2022.10.0"
"cpl-cli==2022.10.0"
],
"PythonVersion": ">=3.10.4",
"PythonPath": {