This commit is contained in:
parent
cc621ce33d
commit
84b5d45f1c
@ -7,3 +7,6 @@ logging.basicConfig(
|
|||||||
)
|
)
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
from .app import Application as BaseApplication
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
import uuid
|
import uuid
|
||||||
|
import base64
|
||||||
import dataset
|
import dataset
|
||||||
from aiohttp import web
|
from aiohttp import web
|
||||||
|
|
||||||
@ -20,22 +20,22 @@ class BaseApplication(web.Application):
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
username=None,
|
basic_username=None,
|
||||||
password=None,
|
basic_password=None,
|
||||||
cookie_name=None,
|
cookie_name=None,
|
||||||
session=None,
|
session=None,
|
||||||
*args,
|
*args,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
):
|
):
|
||||||
self.cookie_name = cookie_name or str(uuid.uuid4())
|
self.cookie_name = cookie_name or str(uuid.uuid4())
|
||||||
self.username = username
|
self.basic_username = basic_username
|
||||||
self.password = password
|
self.basic_password = basic_password
|
||||||
self.session = session or {}
|
self.session = session or {}
|
||||||
middlewares = kwargs.pop("middlewares", [])
|
middlewares = kwargs.pop("middlewares", [])
|
||||||
middlewares.append(self.request_middleware)
|
middlewares.append(self.request_middleware)
|
||||||
middlewares.append(self.base64_auth_middleware)
|
middlewares.append(self.base64_auth_middleware)
|
||||||
middlewares.append(self.session_middleware)
|
middlewares.append(self.session_middleware)
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(middlewares=middlewares,*args, **kwargs)
|
||||||
|
|
||||||
def run(self, *args, **kwargs):
|
def run(self, *args, **kwargs):
|
||||||
web.run_app(self, *args, **kwargs)
|
web.run_app(self, *args, **kwargs)
|
||||||
@ -44,7 +44,7 @@ class BaseApplication(web.Application):
|
|||||||
return self.username == username and self.password == password
|
return self.username == username and self.password == password
|
||||||
|
|
||||||
@web.middleware
|
@web.middleware
|
||||||
async def base64_auth_middleware(request, handler):
|
async def base64_auth_middleware(self, request, handler):
|
||||||
auth_header = request.headers.get("Authorization")
|
auth_header = request.headers.get("Authorization")
|
||||||
if not self.username:
|
if not self.username:
|
||||||
return await handler(request)
|
return await handler(request)
|
||||||
|
Loading…
Reference in New Issue
Block a user