Rewrite: done?

rewrite
Karchnu 2020-11-22 13:34:44 +01:00
parent fcf165de73
commit db827359ee
3 changed files with 19 additions and 31 deletions

View File

@ -21,28 +21,8 @@ class Baguette::Configuration
end
end
module AuthD
class Exception < ::Exception
end
class UserNotFound < ::Exception
end
class AuthenticationInfoLacking < ::Exception
end
# Not used for now.
class NotLoggedException < ::Exception
end
# Not used for now.
class AuthorizationException < ::Exception
end
# Not used for now.
class AdminAuthorizationException < ::Exception
end
end
# Requests and responses.
require "./exceptions"
# Requests and responses.
require "./network"

13
src/exceptions.cr Normal file
View File

@ -0,0 +1,13 @@
module AuthD
class Exception < ::Exception
end
class UserNotFound < ::Exception
end
class AuthenticationInfoLacking < ::Exception
end
class AdminAuthorizationException < ::Exception
end
end

View File

@ -29,8 +29,6 @@ class Baguette::Configuration
end
end
require "./network"
# Provides a JWT-based authentication scheme for service-specific users.
class AuthD::Service < IPC::Server
property configuration : Baguette::Configuration::Auth
@ -94,15 +92,12 @@ class AuthD::Service < IPC::Server
rescue e : UserNotFound
Baguette::Log.error "#{request_name} user not found"
AuthD::Response::Error.new "authorization error"
rescue e : AuthorizationException
Baguette::Log.error "#{request_name} authorization error"
rescue e : AuthenticationInfoLacking
Baguette::Log.error "#{request_name} lacking authentication info"
AuthD::Response::Error.new "authorization error"
rescue e : AdminAuthorizationException
Baguette::Log.error "#{request_name} no admin authorization"
AuthD::Response::Error.new "admin authorization error"
rescue e : NotLoggedException
Baguette::Log.error "#{request_name} user not logged"
AuthD::Response::Error.new "user not logged"
Baguette::Log.error "#{request_name} admin authentication failed"
AuthD::Response::Error.new "authorization error"
rescue e
Baguette::Log.error "#{request_name} generic error #{e}"
AuthD::Response::Error.new "unknown error"