mirror of
https://github.com/netinvent/npbackup.git
synced 2025-10-11 05:57:48 +08:00
Reformat file with black
This commit is contained in:
parent
76f591d943
commit
b0fc5031a8
1 changed files with 18 additions and 7 deletions
|
@ -62,17 +62,22 @@ security = HTTPBasic()
|
||||||
def get_current_username(credentials: HTTPBasicCredentials = Depends(security)):
|
def get_current_username(credentials: HTTPBasicCredentials = Depends(security)):
|
||||||
authenticated_user = None
|
authenticated_user = None
|
||||||
|
|
||||||
|
|
||||||
for user in config_dict["http_server"]["users"]:
|
for user in config_dict["http_server"]["users"]:
|
||||||
try:
|
try:
|
||||||
if secrets.compare_digsest(credentials.username.encode("utf-8"), user.encode("utf-8")):
|
if secrets.compare_digsest(
|
||||||
if secrets.compare_digest(credentials.password.encode("utf-8"), config_dict["http_server"]["users"]["user"]["password"].encode("utf-8")):
|
credentials.username.encode("utf-8"), user.encode("utf-8")
|
||||||
|
):
|
||||||
|
if secrets.compare_digest(
|
||||||
|
credentials.password.encode("utf-8"),
|
||||||
|
config_dict["http_server"]["users"]["user"]["password"].encode(
|
||||||
|
"utf-8"
|
||||||
|
),
|
||||||
|
):
|
||||||
authenticated_user = user
|
authenticated_user = user
|
||||||
break
|
break
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
logger.info(f"Failed to check user: {exc}")
|
logger.info(f"Failed to check user: {exc}")
|
||||||
|
|
||||||
|
|
||||||
if authenticated_user is None:
|
if authenticated_user is None:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||||
|
@ -155,7 +160,9 @@ async def current_version(
|
||||||
client_ip = request.client.host
|
client_ip = request.client.host
|
||||||
|
|
||||||
try:
|
try:
|
||||||
has_permission = True if audience.value in get_user_permissions(auth)["audience"] else False
|
has_permission = (
|
||||||
|
True if audience.value in get_user_permissions(auth)["audience"] else False
|
||||||
|
)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
logger.error(f"Failed to get user permissions: {exc}")
|
logger.error(f"Failed to get user permissions: {exc}")
|
||||||
has_permission = False
|
has_permission = False
|
||||||
|
@ -253,7 +260,9 @@ async def upgrades(
|
||||||
client_ip = request.client.host
|
client_ip = request.client.host
|
||||||
|
|
||||||
try:
|
try:
|
||||||
has_permission = True if audience.value in get_user_permissions(auth)["audience"] else False
|
has_permission = (
|
||||||
|
True if audience.value in get_user_permissions(auth)["audience"] else False
|
||||||
|
)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
logger.error(f"Failed to get user permissions: {exc}")
|
logger.error(f"Failed to get user permissions: {exc}")
|
||||||
has_permission = False
|
has_permission = False
|
||||||
|
@ -353,7 +362,9 @@ async def download(
|
||||||
client_ip = request.client.host
|
client_ip = request.client.host
|
||||||
|
|
||||||
try:
|
try:
|
||||||
has_permission = True if audience.value in get_user_permissions(auth)["audience"] else False
|
has_permission = (
|
||||||
|
True if audience.value in get_user_permissions(auth)["audience"] else False
|
||||||
|
)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
logger.error(f"Failed to get user permissions: {exc}")
|
logger.error(f"Failed to get user permissions: {exc}")
|
||||||
has_permission = False
|
has_permission = False
|
||||||
|
|
Loading…
Add table
Reference in a new issue