This commit is contained in:
yumoqing 2023-10-23 17:32:35 +08:00
parent dcfc9d7ae6
commit bf71b10ab0
2 changed files with 14 additions and 19 deletions

View File

@ -85,16 +85,26 @@ class AuthAPI(AppLogger):
@web.middleware @web.middleware
async def checkAuth(self,request,handler): async def checkAuth(self,request,handler):
print('checkAuth() called ..................') self.info(f'checkAuth() called ...{request.path}')
t1 = time.time()
path = request.path path = request.path
user = await auth.get_auth(request) user = await auth.get_auth(request)
is_ok = await self.checkUserPermission(user, path) is_ok = await self.checkUserPermission(user, path)
t2 = time.time()
if is_ok: if is_ok:
return await handler(request) try:
ret = await handler(request)
t3 = time.time()
self.info(f'timecost={user} access {path} cost {t3-t1}, ({t2-t1})')
return ret
except Exception as e:
self.info(f'timecost={user} access {path} cost {t3-t1}, ({t2-t1}), except={e}')
raise e
if user is None: if user is None:
print(f'**{user=}, {path} need login**') self.info(f'timecost={user} access need login to access {path} ({t2-t1})')
raise web.HTTPUnauthorized raise web.HTTPUnauthorized
print(f'**{user=}, {path} forbidden**') self.info(f'timecost={user} access {path} forbidden ({t2-t1})')
raise web.HTTPForbidden() raise web.HTTPForbidden()
async def needAuth(self,path): async def needAuth(self,path):

View File

@ -165,21 +165,6 @@ class ProcessorResource(AppLogger, StaticResource,Url2File):
return ns return ns
async def _handle(self,request:Request) -> StreamResponse: async def _handle(self,request:Request) -> StreamResponse:
name = str(request.url)
t = TimeCost(name)
with t:
try:
x = await self._handle1(request)
except Exception as e:
self.error(f'{name}:error={e}')
print_exc()
x = e
self.info(f'{name}:time cost={t.end_time - t.begin_time}')
if not isinstance(x, StreamResponse):
return HTTPException
return x
async def _handle1(self,request:Request) -> StreamResponse:
clientkeys = { clientkeys = {
"iPhone":"iphone", "iPhone":"iphone",
"iPad":"ipad", "iPad":"ipad",