auth.py: Make usage of exceptions instead of if-else-blocks #5

Closed
frlan wants to merge 1 commits from auth-with-exceptions into main
Owner
No description provided.
frlan added 1 commit 2021-06-21 16:03:26 +02:00
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is passing Details
35cafe1780
auth.py: Make usage of exceptions instead of if-else-blocks
weeman reviewed 2021-06-21 17:07:50 +02:00
@ -18,2 +32,3 @@
if auth_user["password"] != password:
except (UserWrongCredentialsException, KeyError):
print('Wrong username/password combination')
Owner

Ich bau die Tage mal logging ein.

Was passiert bei der API mit print? Sehe ich das dann in der Antwort? Weil es sollte irgend ein geregeltes JSON zurückkommen.

Ich bau die Tage mal `logging` ein. Was passiert bei der API mit `print`? Sehe ich das dann in der Antwort? Weil es sollte irgend ein geregeltes JSON zurückkommen.
Owner

Siehe #7 für Ausgaben.

Siehe #7 für Ausgaben.
weeman reviewed 2021-06-21 17:08:36 +02:00
@ -16,0 +22,4 @@
users = yaml.safe_load(auth_file_stream)
except yaml.YAMLError:
print('Could not parse auth.yml.')
Owner

Hier würde ich dann eine 500er Antwort zurückgeben.

Hier würde ich dann eine 500er Antwort zurückgeben.
Author
Owner

Ich habe das jetzt mal versucht -- aber das ist nicht so richtig schön zu machen, wenn man nicht den kompletten Code in die routes.py verlegen will oder Datenstrutkturen von links nach rechts kopieren mag. Ich würde das mal rauslassen bis LDAP eingebaut wird. Für dev sollte das vollkommen ok sein.

Ich habe das jetzt mal versucht -- aber das ist nicht so richtig schön zu machen, wenn man nicht den kompletten Code in die routes.py verlegen will oder Datenstrutkturen von links nach rechts kopieren mag. Ich würde das mal rauslassen bis LDAP eingebaut wird. Für dev sollte das vollkommen ok sein.
Owner

Ich hab da ne Idee. Mach ich später

Ich hab da ne Idee. Mach ich später
weeman marked this conversation as resolved
weeman requested changes 2021-06-21 17:10:32 +02:00
@ -16,0 +25,4 @@
print('Could not parse auth.yml.')
try:
auth_user = users[username]
Owner

Die Prüfung, ob der Benutzer existiert ist verschwunden oder übersehe ich was?

Die Prüfung, ob der Benutzer existiert ist verschwunden oder übersehe ich was?
Author
Owner

Ja, das ist richtig. Das wirft einen KeyError.

Ja, das ist richtig. Das wirft einen KeyError.
weeman marked this conversation as resolved
frlan closed this pull request 2022-01-23 21:55:19 +01:00
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
Required
Details

Pull request closed

Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: kompetenzinventar/ki-backend#5
No description provided.