Skip to content

Commit

Permalink
Flip if statement to simplify things
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtomlinson committed May 24, 2022
1 parent f8fef3b commit 37eabda
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions distributed/http/scheduler/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,27 @@ def require_auth(method_func):
def wrapper(self):
auth = self.request.headers.get("Authorization", None)
key = dask.config.get("distributed.scheduler.http.api-key")
if (
key is None
or key == ""
or (
key
and (
not auth
or not auth.startswith("Bearer ")
or key != auth.split(" ")[-1]
)
)
if key is False or (
key and auth and auth.startswith("Bearer ") and key == auth.split(" ")[-1]
):
self.set_status(403, "Unauthorized")
return
if not asyncio.iscoroutinefunction(method_func):
return method_func(self)
else:

if not asyncio.iscoroutinefunction(method_func):
return method_func(self)
else:
async def tmp():
return await method_func(self)

async def tmp():
return await method_func(self)
return tmp()
else:
self.set_status(403, "Unauthorized")
if not asyncio.iscoroutinefunction(method_func):
return
else:
# When wrapping a coroutine we need to return a coroutine even if it just returns None
async def tmp():
return

return tmp()
return tmp()

return wrapper

Expand Down

0 comments on commit 37eabda

Please sign in to comment.