Skip to content
This repository was archived by the owner on Jan 9, 2026. It is now read-only.

Commit 3caea5d

Browse files
committed
simplify returns
1 parent 0eff0b8 commit 3caea5d

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

zodiac/gateway/service_library.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,27 +63,29 @@ def check_service_auth(service, request):
6363

6464
elif service.plugin == ServiceRegistry.BASIC_AUTH:
6565
auth = BasicAuthentication()
66+
msg = False, "Permission not allowed"
6667
try:
6768
user, password = auth.authenticate(request)
6869
except Exception:
6970
return False, "Authentication credentials were not provided."
7071
if service.source.filter(user=user):
71-
return True, ""
72-
else:
73-
return False, "Permission not allowed"
72+
msg = True, ""
73+
return msg
7474
elif service.plugin == ServiceRegistry.KEY_AUTH:
7575
apikey = request.META.get("HTTP_APIKEY")
7676
sources = service.sources.all()
77+
msg = False, "API Key needed."
7778
for source in sources:
7879
if apikey == source.apikey:
79-
return True, ""
80-
return False, "API Key needed."
80+
msg = True, ""
81+
return msg
8182
elif service.plugin == ServiceRegistry.SERVER_AUTH:
8283
source = service.sources.all()
84+
msg = True, ""
8385
if not source:
84-
return False, "Source needed."
86+
msg = False, "Source needed."
8587
request.META["HTTP_AUTHORIZATION"] = requests.auth._basic_auth_str(
8688
source[0].user.username, source[0].apikey)
87-
return True, ""
89+
return msg
8890
else:
8991
raise NotImplementedError("Plugin %d not implemented" % service.plugin)

0 commit comments

Comments
 (0)