Esempio n. 1
0
def debugpy_init(port=5678):
    if get_environment() == "development":
        import debugpy

        print("running in debug mode")
        try:
            debugpy.listen(("0.0.0.0", port))
            debugpy.wait_for_client()
        except Exception:
            print(f"debugpy attach on port {port} aborted")
Esempio n. 2
0
def ptvsd_debugger_init(port=5678, wait_seconds=3):
    if get_environment() == "development":
        import ptvsd

        print("running in debug mode")
        try:
            ptvsd.enable_attach(address=("0.0.0.0", port))
            ptvsd.wait_for_attach(wait_seconds)
        except Exception:
            print(f"ptvsd attach on port {port} aborted")
            pass
Esempio n. 3
0
    async def auth_middleware(request, handler):
        request.user = None
        try:
            token = request.headers.get("authorization", None).split(" ")[1]
            if token == "TEST" and get_environment() == "development":
                request.user = {
                    "name": "Test",
                    "permissions": ["read:live", "read:history"],
                }
                return await handler(request)
            unverified_header = jwt.get_unverified_header(token)
        except Exception:
            return await handler(request)
        rsa_key = await validate_header(unverified_header)
        if rsa_key:
            try:
                payload = jwt.decode(
                    token,
                    jwt.algorithms.RSAAlgorithm.from_jwk(json.dumps(rsa_key)),
                    algorithms=[JWT_ALGORITHM],
                    audience=API_AUDIENCE,
                    issuer=f"https://{AUTH0_DOMAIN}/",
                )
            except jwt.ExpiredSignatureError:
                return web.json_response({"message": "token is expired"}, status=401)
            except (jwt.InvalidAudienceError, jwt.InvalidIssuerError):
                return web.json_response(
                    {
                        "message": "Incorrect claims, please check the audience and issuer"
                    },
                    status=401,
                )
            except Exception:
                return web.json_response(
                    {"message": "Unable to parse authentication token."}, status=401
                )

            request.user = payload
        return await handler(request)
Esempio n. 4
0
from aiohttp import web

import aiohttp_cors
import asyncio
from dbmodels.db import init_middleware
from server.security import get_middleware
from server.routes import routes
from utils.timeseries.timescale_utils import pool_context

# Load encrypted config
from secrets_management.manage import decrypt_credentials, load_credentials, get_environment


if get_environment() == 'development':
    import ptvsd
    print('running in debug mode')
    try:
        ptvsd.enable_attach(address=('0.0.0.0', 5678))
        ptvsd.wait_for_attach(3)
    except:
        print('ptvsd attach aborted')
        pass

load_credentials(decrypt_credentials(which=['*.env']))

print('Initializing middlewares...')
auth_middleware = asyncio.get_event_loop().run_until_complete(get_middleware())

app = web.Application(middlewares=[auth_middleware])
db_middleware = init_middleware(app)
app.middlewares.append(db_middleware)
Esempio n. 5
0
import aiohttp
from aiohttp import web

from dbmodels.db import init_middleware
from secrets_management.manage import (
    decrypt_credentials,
    load_credentials,
    get_environment,
)
from ticker.main_loop import Ticker


if get_environment() == "development":
    import ptvsd

    print("[Scheduler] debug mode")
    try:
        ptvsd.enable_attach(address=("0.0.0.0", 5680))
        ptvsd.wait_for_attach(8)
    except Exception as e:
        print(e)
        print("[Scheduler] ptvsd attach aborted")


load_credentials(decrypt_credentials(which=["*.env"]))

app = web.Application()
db_middleware = init_middleware(app)
app.middlewares.append(db_middleware)