[WIP] Added auth controller & updated pakages #70
This commit is contained in:
parent
91b054fdca
commit
411e44a681
@ -1,8 +1,10 @@
|
|||||||
import sys
|
import sys
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
|
from blinker import Namespace
|
||||||
from cpl_core.dependency_injection import ServiceProviderABC
|
from cpl_core.dependency_injection import ServiceProviderABC
|
||||||
from flask import Flask, request
|
from flask import Flask, request
|
||||||
|
from flask_cors import CORS
|
||||||
|
|
||||||
from bot_api.configuration.api_settings import ApiSettings
|
from bot_api.configuration.api_settings import ApiSettings
|
||||||
from bot_api.logging.api_logger import ApiLogger
|
from bot_api.logging.api_logger import ApiLogger
|
||||||
@ -27,20 +29,26 @@ class Api(Flask):
|
|||||||
self._services = services
|
self._services = services
|
||||||
self._apt_settings = api_settings
|
self._apt_settings = api_settings
|
||||||
|
|
||||||
|
self._cors = CORS(self, support_credentials=True)
|
||||||
|
|
||||||
# register before request
|
# register before request
|
||||||
self.before_request_funcs.setdefault(None, []).append(self.before_request)
|
self.before_request_funcs.setdefault(None, []).append(self.before_request)
|
||||||
|
my_signals = Namespace()
|
||||||
|
notify = my_signals.signal('notify')
|
||||||
|
|
||||||
def _register_routes(self):
|
def _register_routes(self):
|
||||||
for path, f in Route.registered_routes.items():
|
for path, f in Route.registered_routes.items():
|
||||||
|
route = f[0]
|
||||||
|
kwargs = f[1]
|
||||||
cls = None
|
cls = None
|
||||||
qual_name_split = f.__qualname__.split('.')
|
qual_name_split = route.__qualname__.split('.')
|
||||||
if len(qual_name_split) > 0:
|
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)
|
cls = self._services.get_service(cls_type)
|
||||||
|
|
||||||
partial_f = partial(f, self if cls is None else cls)
|
partial_f = partial(route, self if cls is None else cls)
|
||||||
partial_f.__name__ = f.__name__
|
partial_f.__name__ = route.__name__
|
||||||
self.route(path)(partial_f)
|
self.route(path, **kwargs)(partial_f)
|
||||||
|
|
||||||
def before_request(self, *args, **kwargs):
|
def before_request(self, *args, **kwargs):
|
||||||
self._logger.debug(__name__, f'Received GET @{request.url}')
|
self._logger.debug(__name__, f'Received GET @{request.url}')
|
||||||
|
@ -10,6 +10,7 @@ from flask import Flask
|
|||||||
from bot_api.api import Api
|
from bot_api.api import Api
|
||||||
from bot_api.api_thread import ApiThread
|
from bot_api.api_thread import ApiThread
|
||||||
from bot_api.controller.api_controller import ApiController
|
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.abc.module_abc import ModuleABC
|
||||||
from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
|
from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
|
||||||
|
|
||||||
@ -33,4 +34,5 @@ class ApiModule(ModuleABC):
|
|||||||
services.add_singleton(ApiThread)
|
services.add_singleton(ApiThread)
|
||||||
services.add_singleton(Flask, Api)
|
services.add_singleton(Flask, Api)
|
||||||
|
|
||||||
|
services.add_transient(AuthController)
|
||||||
services.add_transient(ApiController)
|
services.add_transient(ApiController)
|
||||||
|
@ -17,11 +17,14 @@
|
|||||||
"LicenseDescription": "",
|
"LicenseDescription": "",
|
||||||
"Dependencies": [
|
"Dependencies": [
|
||||||
"cpl-core==2022.10.0.post6",
|
"cpl-core==2022.10.0.post6",
|
||||||
|
"Flask==2.2.2",
|
||||||
"Flask[async]==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": [
|
"DevDependencies": [
|
||||||
"cpl-cli>=2022.10.0"
|
"cpl-cli==2022.10.0"
|
||||||
],
|
],
|
||||||
"PythonVersion": ">=3.10.4",
|
"PythonVersion": ">=3.10.4",
|
||||||
"PythonPath": {
|
"PythonPath": {
|
||||||
|
@ -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
|
# imports
|
||||||
|
|
||||||
|
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||||
|
version_info = VersionInfo(major='0', minor='2', micro='3')
|
||||||
|
47
src/bot_api/controller/auth_controller.py
Normal file
47
src/bot_api/controller/auth_controller.py
Normal 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()
|
@ -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')
|
@ -2,10 +2,10 @@ class Route:
|
|||||||
registered_routes = {}
|
registered_routes = {}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def route(cls, path=None):
|
def route(cls, path=None, **kwargs):
|
||||||
# simple decorator for class based views
|
# simple decorator for class based views
|
||||||
def inner(fn):
|
def inner(fn):
|
||||||
cls.registered_routes[path] = fn
|
cls.registered_routes[path] = (fn, kwargs)
|
||||||
return fn
|
return fn
|
||||||
|
|
||||||
return inner
|
return inner
|
||||||
|
@ -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
|
# imports
|
||||||
|
|
||||||
|
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||||
|
version_info = VersionInfo(major='0', minor='2', micro='3')
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
"cpl-core>=2022.10.0"
|
"cpl-core>=2022.10.0"
|
||||||
],
|
],
|
||||||
"DevDependencies": [
|
"DevDependencies": [
|
||||||
"cpl-cli>=2022.10.0"
|
"cpl-cli==2022.10.0"
|
||||||
],
|
],
|
||||||
"PythonVersion": ">=3.10.4",
|
"PythonVersion": ">=3.10.4",
|
||||||
"PythonPath": {
|
"PythonPath": {
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
"cpl-core>=2022.10.0"
|
"cpl-core>=2022.10.0"
|
||||||
],
|
],
|
||||||
"DevDependencies": [
|
"DevDependencies": [
|
||||||
"cpl-cli>=2022.10.0"
|
"cpl-cli==2022.10.0"
|
||||||
],
|
],
|
||||||
"PythonVersion": ">=3.10.4",
|
"PythonVersion": ">=3.10.4",
|
||||||
"PythonPath": {
|
"PythonPath": {
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
"cpl-core>=2022.10.0.post5"
|
"cpl-core>=2022.10.0.post5"
|
||||||
],
|
],
|
||||||
"DevDependencies": [
|
"DevDependencies": [
|
||||||
"cpl-cli>=2022.10.0"
|
"cpl-cli==2022.10.0"
|
||||||
],
|
],
|
||||||
"PythonVersion": ">=3.10.4",
|
"PythonVersion": ">=3.10.4",
|
||||||
"PythonPath": {
|
"PythonPath": {
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
"cpl-core>=2022.10.0.post5"
|
"cpl-core>=2022.10.0.post5"
|
||||||
],
|
],
|
||||||
"DevDependencies": [
|
"DevDependencies": [
|
||||||
"cpl-cli>=2022.10.0"
|
"cpl-cli==2022.10.0"
|
||||||
],
|
],
|
||||||
"PythonVersion": ">=3.10.4",
|
"PythonVersion": ">=3.10.4",
|
||||||
"PythonPath": {
|
"PythonPath": {
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
"cpl-core>=2022.10.0.post2"
|
"cpl-core>=2022.10.0.post2"
|
||||||
],
|
],
|
||||||
"DevDependencies": [
|
"DevDependencies": [
|
||||||
"cpl-cli>=2022.10.0"
|
"cpl-cli==2022.10.0"
|
||||||
],
|
],
|
||||||
"PythonVersion": ">=3.10.4",
|
"PythonVersion": ">=3.10.4",
|
||||||
"PythonPath": {
|
"PythonPath": {
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
"cpl-core>=2022.10.0.post2"
|
"cpl-core>=2022.10.0.post2"
|
||||||
],
|
],
|
||||||
"DevDependencies": [
|
"DevDependencies": [
|
||||||
"cpl-cli>=2022.10.0"
|
"cpl-cli==2022.10.0"
|
||||||
],
|
],
|
||||||
"PythonVersion": ">=3.10.4",
|
"PythonVersion": ">=3.10.4",
|
||||||
"PythonPath": {
|
"PythonPath": {
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
"cpl-core>=2022.10.0.post2"
|
"cpl-core>=2022.10.0.post2"
|
||||||
],
|
],
|
||||||
"DevDependencies": [
|
"DevDependencies": [
|
||||||
"cpl-cli>=2022.10.0"
|
"cpl-cli==2022.10.0"
|
||||||
],
|
],
|
||||||
"PythonVersion": ">=3.10.4",
|
"PythonVersion": ">=3.10.4",
|
||||||
"PythonPath": {
|
"PythonPath": {
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
"cpl-core>=2022.10.0.post5"
|
"cpl-core>=2022.10.0.post5"
|
||||||
],
|
],
|
||||||
"DevDependencies": [
|
"DevDependencies": [
|
||||||
"cpl-cli>=2022.10.0"
|
"cpl-cli==2022.10.0"
|
||||||
],
|
],
|
||||||
"PythonVersion": ">=3.10.4",
|
"PythonVersion": ">=3.10.4",
|
||||||
"PythonPath": {
|
"PythonPath": {
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
"cpl-core>=2022.10.0.post2"
|
"cpl-core>=2022.10.0.post2"
|
||||||
],
|
],
|
||||||
"DevDependencies": [
|
"DevDependencies": [
|
||||||
"cpl-cli>=2022.10.0"
|
"cpl-cli==2022.10.0"
|
||||||
],
|
],
|
||||||
"PythonVersion": ">=3.10.4",
|
"PythonVersion": ">=3.10.4",
|
||||||
"PythonPath": {
|
"PythonPath": {
|
||||||
|
Loading…
Reference in New Issue
Block a user