diff --git a/diana_services_api/app.py b/diana_services_api/app.py deleted file mode 100644 index d15dd8f..0000000 --- a/diana_services_api/app.py +++ /dev/null @@ -1,89 +0,0 @@ -# NEON AI (TM) SOFTWARE, Software Development Kit & Application Development System -# All trademark and other rights reserved by their respective owners -# Copyright 2008-2021 Neongecko.com Inc. -# BSD-3 -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# 1. Redistributions of source code must retain the above copyright notice, -# this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# 3. Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from this -# software without specific prior written permission. -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, -# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -from fastapi import FastAPI, Depends - -from diana_services_api.schema.auth_requests import * -from diana_services_api.schema.api_requests import * -from diana_services_api.schema.api_responses import * -from diana_services_api.mq_service_api import MQServiceManager -from diana_services_api.auth.client_manager import ClientManager, JWTBearer - - -def create_app(): - mq_connector = MQServiceManager() - client_manager = ClientManager() - jwt_bearer = JWTBearer(client_manager) - app = FastAPI() - - @app.post("/auth/login") - async def check_login(request: AuthenticationRequest) -> AuthenticationResponse: - return client_manager.check_auth_request(**dict(request)) - - @app.post("/proxy/weather", dependencies=[Depends(jwt_bearer)]) - async def api_proxy_weather(query: WeatherAPIRequest) -> WeatherAPIOnecallResponse: - return mq_connector.query_api_proxy("open_weather_map", dict(query)) - - @app.post("/proxy/stock/symbol", dependencies=[Depends(jwt_bearer)]) - async def api_proxy_stock_symbol(query: StockAPISymbolRequest) -> StockAPISearchResponse: - return mq_connector.query_api_proxy("alpha_vantage", - {**dict(query), - **{"api": "symbol"}}) - - @app.post("/proxy/stock/quote", dependencies=[Depends(jwt_bearer)]) - async def api_proxy_stock_quote(query: StockAPIQuoteRequest) -> StockAPIQuoteResponse: - return mq_connector.query_api_proxy("alpha_vantage", - {**dict(query), **{"api": "quote"}}) - - @app.post("/proxy/geolocation/geocode", dependencies=[Depends(jwt_bearer)]) - async def api_proxy_geolocation(query: GeoAPIRequest) -> GeoAPIGeocodeResponse: - return mq_connector.query_api_proxy("map_maker", dict(query)) - - @app.post("/proxy/geolocation/reverse", dependencies=[Depends(jwt_bearer)]) - async def api_proxy_geolocation(query: GeoAPIReverseRequest) -> GeoAPIReverseResponse: - return mq_connector.query_api_proxy("map_maker", dict(query)) - - @app.post("/proxy/wolframalpha", dependencies=[Depends(jwt_bearer)]) - async def api_proxy_wolframalpha(query: WolframAlphaAPIRequest) -> WolframAlphaAPIResponse: - return mq_connector.query_api_proxy("wolfram_alpha", dict(query)) - - @app.post("/email", dependencies=[Depends(jwt_bearer)]) - async def email_send(request: SendEmailRequest): - mq_connector.send_email(**dict(request)) - - @app.post("/metrics/upload", dependencies=[Depends(jwt_bearer)]) - async def upload_metric(metric: UploadMetricRequest): - mq_connector.upload_metric(**dict(metric)) - - @app.post("/ccl/parse", dependencies=[Depends(jwt_bearer)]) - async def parse_nct_script(script: ParseScriptRequest) -> ScriptParserResponse: - return mq_connector.parse_ccl_script(**dict(script)) - - @app.post("/coupons", dependencies=[Depends(jwt_bearer)]) - async def get_coupons() -> CouponsResponse: - return mq_connector.get_coupons() - - return app diff --git a/diana_services_api/app/__init__.py b/diana_services_api/app/__init__.py new file mode 100644 index 0000000..44970f8 --- /dev/null +++ b/diana_services_api/app/__init__.py @@ -0,0 +1,41 @@ +# NEON AI (TM) SOFTWARE, Software Development Kit & Application Development System +# All trademark and other rights reserved by their respective owners +# Copyright 2008-2021 Neongecko.com Inc. +# BSD-3 +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# 3. Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, +# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +from fastapi import FastAPI + +from diana_services_api.app.dependencies import client_manager, jwt_bearer, mq_connector +from diana_services_api.app.routers.api_proxy import proxy_route +from diana_services_api.app.routers.mq_backend import mq_route +from diana_services_api.app.routers.auth import auth_route + + +def create_app(): + app = FastAPI() + app.include_router(auth_route) + app.include_router(proxy_route) + app.include_router(mq_route) + + return app diff --git a/diana_services_api/__main__.py b/diana_services_api/app/__main__.py similarity index 98% rename from diana_services_api/__main__.py rename to diana_services_api/app/__main__.py index 951b1d8..ab95303 100644 --- a/diana_services_api/__main__.py +++ b/diana_services_api/app/__main__.py @@ -31,6 +31,7 @@ def main(): app = create_app() + # TODO: host, port from config uvicorn.run(app, host="0.0.0.0", port=8080) diff --git a/diana_services_api/app/dependencies.py b/diana_services_api/app/dependencies.py new file mode 100644 index 0000000..926a177 --- /dev/null +++ b/diana_services_api/app/dependencies.py @@ -0,0 +1,33 @@ +# NEON AI (TM) SOFTWARE, Software Development Kit & Application Development System +# All trademark and other rights reserved by their respective owners +# Copyright 2008-2021 Neongecko.com Inc. +# BSD-3 +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# 3. Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, +# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +from diana_services_api.mq_service_api import MQServiceManager +from diana_services_api.auth.client_manager import ClientManager, UserTokenAuth + +config = dict() # TODO +mq_connector = MQServiceManager(config) +client_manager = ClientManager(config) +jwt_bearer = UserTokenAuth(client_manager) diff --git a/diana_services_api/app/routers/__init__.py b/diana_services_api/app/routers/__init__.py new file mode 100644 index 0000000..d782cbb --- /dev/null +++ b/diana_services_api/app/routers/__init__.py @@ -0,0 +1,25 @@ +# NEON AI (TM) SOFTWARE, Software Development Kit & Application Development System +# All trademark and other rights reserved by their respective owners +# Copyright 2008-2021 Neongecko.com Inc. +# BSD-3 +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# 3. Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, +# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/diana_services_api/app/routers/api_proxy.py b/diana_services_api/app/routers/api_proxy.py new file mode 100644 index 0000000..d263338 --- /dev/null +++ b/diana_services_api/app/routers/api_proxy.py @@ -0,0 +1,67 @@ +# NEON AI (TM) SOFTWARE, Software Development Kit & Application Development System +# All trademark and other rights reserved by their respective owners +# Copyright 2008-2021 Neongecko.com Inc. +# BSD-3 +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# 3. Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, +# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +from fastapi import APIRouter, Depends +from diana_services_api.schema.api_requests import * +from diana_services_api.schema.api_responses import * +from diana_services_api.app.dependencies import jwt_bearer, mq_connector + + +proxy_route = APIRouter(prefix="/proxy", tags=["backend"], + dependencies=[Depends(jwt_bearer)]) + + +@proxy_route.post("/weather") +async def api_proxy_weather(query: WeatherAPIRequest) -> WeatherAPIOnecallResponse: + return mq_connector.query_api_proxy("open_weather_map", dict(query)) + + +@proxy_route.post("/stock/symbol") +async def api_proxy_stock_symbol(query: StockAPISymbolRequest) -> StockAPISearchResponse: + return mq_connector.query_api_proxy("alpha_vantage", + {**dict(query), + **{"api": "symbol"}}) + + +@proxy_route.post("/stock/quote") +async def api_proxy_stock_quote(query: StockAPIQuoteRequest) -> StockAPIQuoteResponse: + return mq_connector.query_api_proxy("alpha_vantage", + {**dict(query), **{"api": "quote"}}) + + +@proxy_route.post("/geolocation/geocode") +async def api_proxy_geolocation(query: GeoAPIRequest) -> GeoAPIGeocodeResponse: + return mq_connector.query_api_proxy("map_maker", dict(query)) + + +@proxy_route.post("/geolocation/reverse") +async def api_proxy_geolocation(query: GeoAPIReverseRequest) -> GeoAPIReverseResponse: + return mq_connector.query_api_proxy("map_maker", dict(query)) + + +@proxy_route.post("/wolframalpha") +async def api_proxy_wolframalpha(query: WolframAlphaAPIRequest) -> WolframAlphaAPIResponse: + return mq_connector.query_api_proxy("wolfram_alpha", dict(query)) \ No newline at end of file diff --git a/diana_services_api/app/routers/auth.py b/diana_services_api/app/routers/auth.py new file mode 100644 index 0000000..6d1b8f1 --- /dev/null +++ b/diana_services_api/app/routers/auth.py @@ -0,0 +1,37 @@ +# NEON AI (TM) SOFTWARE, Software Development Kit & Application Development System +# All trademark and other rights reserved by their respective owners +# Copyright 2008-2021 Neongecko.com Inc. +# BSD-3 +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# 3. Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, +# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +from fastapi import APIRouter + +from diana_services_api.app.dependencies import client_manager +from diana_services_api.schema.auth_requests import * + +auth_route = APIRouter(prefix="/auth", tags=["authentication"]) + + +@auth_route.post("/login") +async def check_login(request: AuthenticationRequest) -> AuthenticationResponse: + return client_manager.check_auth_request(**dict(request)) diff --git a/diana_services_api/app/routers/mq_backend.py b/diana_services_api/app/routers/mq_backend.py new file mode 100644 index 0000000..1d11546 --- /dev/null +++ b/diana_services_api/app/routers/mq_backend.py @@ -0,0 +1,53 @@ +# NEON AI (TM) SOFTWARE, Software Development Kit & Application Development System +# All trademark and other rights reserved by their respective owners +# Copyright 2008-2021 Neongecko.com Inc. +# BSD-3 +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# 3. Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, +# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +from fastapi import APIRouter, Depends +from diana_services_api.schema.api_requests import * +from diana_services_api.schema.api_responses import * +from diana_services_api.app.dependencies import jwt_bearer, mq_connector + + +mq_route = APIRouter(tags=["backend"], dependencies=[Depends(jwt_bearer)]) + + +@mq_route.post("/email", dependencies=[Depends(jwt_bearer)]) +async def email_send(request: SendEmailRequest): + mq_connector.send_email(**dict(request)) + + +@mq_route.post("/metrics/upload", dependencies=[Depends(jwt_bearer)]) +async def upload_metric(metric: UploadMetricRequest): + mq_connector.upload_metric(**dict(metric)) + + +@mq_route.post("/ccl/parse", dependencies=[Depends(jwt_bearer)]) +async def parse_nct_script(script: ParseScriptRequest) -> ScriptParserResponse: + return mq_connector.parse_ccl_script(**dict(script)) + + +@mq_route.post("/coupons", dependencies=[Depends(jwt_bearer)]) +async def get_coupons() -> CouponsResponse: + return mq_connector.get_coupons() diff --git a/diana_services_api/auth/client_manager.py b/diana_services_api/auth/client_manager.py index 626f348..ded3f0c 100644 --- a/diana_services_api/auth/client_manager.py +++ b/diana_services_api/auth/client_manager.py @@ -28,20 +28,21 @@ from time import time from typing import Dict, Optional - from fastapi import Request, HTTPException from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials from jwt import DecodeError class ClientManager: - def __init__(self): + def __init__(self, config: dict): self.authorized_clients: Dict[str, dict] = dict() - # TODO: secrets and expirations from config - self._access_token_lifetime = 3600 * 24 # 1 day - self._refresh_token_lifetime = 3600 * 24 * 7 # 1 week - self._access_secret = 'a800445648142061fc238d1f84e96200da87f4f9f784108ac90db8b4391b117b' - self._refresh_secret = '833d369ac73d883123743a44b4a7fe21203cffc956f4c8a99be6e71aafa8e1aa' + self._access_token_lifetime = config.get("access_token_ttl", 3600 * 24) + self._refresh_token_lifetime = config.get("refresh_token_ttl", + 3600 * 24 * 7) + self._access_secret = config.get("access_token_secret", + 'a800445648142061fc238d1f84e96200da87f4f9f784108ac90db8b4391b117b') + self._refresh_secret = config.get("refresh_token_secret", + '833d369ac73d883123743a44b4a7fe21203cffc956f4c8a99be6e71aafa8e1aa') self._jwt_algo = "HS256" def check_auth_request(self, client_id: str, username: str, @@ -82,14 +83,14 @@ def validate_auth(self, token: str) -> bool: return False -class JWTBearer(HTTPBearer): +class UserTokenAuth(HTTPBearer): def __init__(self, client_manager: ClientManager): HTTPBearer.__init__(self) self.client_manager = client_manager async def __call__(self, request: Request): credentials: HTTPAuthorizationCredentials = \ - await super(JWTBearer, self).__call__(request) + await HTTPBearer.__call__(self, request) if credentials: if not credentials.scheme == "Bearer": raise HTTPException(status_code=403, diff --git a/diana_services_api/mq_service_api.py b/diana_services_api/mq_service_api.py index 760f07d..84dbc20 100644 --- a/diana_services_api/mq_service_api.py +++ b/diana_services_api/mq_service_api.py @@ -39,8 +39,8 @@ class APIError(HTTPException): class MQServiceManager: - def __init__(self): - self.mq_default_timeout = 10 + def __init__(self, config: dict): + self.mq_default_timeout = config.get('mq_default_timeout', 10) def _validate_api_proxy_response(self, response: dict): if response['status_code'] == 200: diff --git a/tests/test_auth.py b/tests/test_auth.py index 823ccd6..f535005 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -30,7 +30,7 @@ class TestClientManager(unittest.TestCase): from diana_services_api.auth.client_manager import ClientManager - client_manager = ClientManager() + client_manager = ClientManager({}) def test_check_auth_request(self): client_1 = str(uuid4())