Select messages to show (IPC and Auth).
This commit is contained in:
parent
e3ef5cb784
commit
0ee755f4e9
@ -12,6 +12,13 @@ class Baguette::Configuration
|
|||||||
property mailer_exe : String = "/usr/local/bin/mailer"
|
property mailer_exe : String = "/usr/local/bin/mailer"
|
||||||
property read_only_profile_keys : Array(String) = Array(String).new
|
property read_only_profile_keys : Array(String) = Array(String).new
|
||||||
|
|
||||||
|
# Handle messages to display and to mask.
|
||||||
|
# Messages to mask, to focus on what is important.
|
||||||
|
property messages_to_mask : Array(AUTHMESSAGE) = [AUTHMESSAGE::KEEPALIVE]
|
||||||
|
|
||||||
|
# Path to the log file. No log file = just print everything.
|
||||||
|
property log_file : String? = nil
|
||||||
|
|
||||||
property print_password_recovery_parameters : Bool = false
|
property print_password_recovery_parameters : Bool = false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -82,6 +82,10 @@ begin
|
|||||||
exit 0
|
exit 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if path = configuration.log_file
|
||||||
|
Baguette::Log.log_path = path
|
||||||
|
end
|
||||||
|
|
||||||
AuthD::Service.new(configuration).run
|
AuthD::Service.new(configuration).run
|
||||||
|
|
||||||
rescue e : OptionParser::Exception
|
rescue e : OptionParser::Exception
|
||||||
|
@ -5,6 +5,25 @@ extend AuthD
|
|||||||
|
|
||||||
require "./configuration"
|
require "./configuration"
|
||||||
|
|
||||||
|
class Array(T)
|
||||||
|
def contains?(value : T)
|
||||||
|
(self.select { |x| x == value }).size > 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# WIP: select (dynamically) messages to mask
|
||||||
|
|
||||||
|
module AuthD
|
||||||
|
enum MESSAGE
|
||||||
|
KEEPALIVE
|
||||||
|
LOGIN
|
||||||
|
# TODO
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
alias IPCMESSAGE = Baguette::Configuration::IPC::MESSAGE
|
||||||
|
alias AUTHMESSAGE = AuthD::MESSAGE
|
||||||
|
|
||||||
# Provides a JWT-based authentication scheme for service-specific users.
|
# Provides a JWT-based authentication scheme for service-specific users.
|
||||||
class AuthD::Service < IPC
|
class AuthD::Service < IPC
|
||||||
property configuration : Baguette::Configuration::Auth
|
property configuration : Baguette::Configuration::Auth
|
||||||
@ -47,6 +66,14 @@ class AuthD::Service < IPC
|
|||||||
self.service_init @configuration.service_name
|
self.service_init @configuration.service_name
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def should_display?(value : AUTHMESSAGE)
|
||||||
|
(@configuration.messages_to_mask.select { |x| x == value }).size == 0
|
||||||
|
end
|
||||||
|
|
||||||
|
def should_display?(value : IPCMESSAGE)
|
||||||
|
@configuration.ipc_messages_to_show.contains? value
|
||||||
|
end
|
||||||
|
|
||||||
def obsolete_hash_password(password : String) : String
|
def obsolete_hash_password(password : String) : String
|
||||||
digest = OpenSSL::Digest.new "sha256"
|
digest = OpenSSL::Digest.new "sha256"
|
||||||
digest << password
|
digest << password
|
||||||
@ -147,7 +174,7 @@ class AuthD::Service < IPC
|
|||||||
if response.is_a? AuthD::Response::Error
|
if response.is_a? AuthD::Response::Error
|
||||||
Baguette::Log.warning "fd #{ "%4d" % event.fd} (#{duration}) #{request_name} >> #{response_name} (#{response.reason})"
|
Baguette::Log.warning "fd #{ "%4d" % event.fd} (#{duration}) #{request_name} >> #{response_name} (#{response.reason})"
|
||||||
else
|
else
|
||||||
if request_name != "KeepAlive" || @configuration.print_keepalive
|
if request_name != "KeepAlive" || should_display? AUTHMESSAGE::KEEPALIVE
|
||||||
Baguette::Log.debug "fd #{ "%4d" % event.fd} (#{duration}) #{request_name} >> #{response_name}"
|
Baguette::Log.debug "fd #{ "%4d" % event.fd} (#{duration}) #{request_name} >> #{response_name}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -174,10 +201,10 @@ class AuthD::Service < IPC
|
|||||||
self.loop do |event|
|
self.loop do |event|
|
||||||
case event.type
|
case event.type
|
||||||
when LibIPC::EventType::Timer
|
when LibIPC::EventType::Timer
|
||||||
Baguette::Log.debug "Timer" if @configuration.print_ipc_timer
|
Baguette::Log.debug "Timer" if should_display? IPCMESSAGE::TIMER
|
||||||
|
|
||||||
when LibIPC::EventType::MessageRx
|
when LibIPC::EventType::MessageRx
|
||||||
Baguette::Log.debug "Received message from #{event.fd}" if @configuration.print_ipc_message_received
|
Baguette::Log.debug "Received message from #{event.fd}" if should_display? IPCMESSAGE::RX
|
||||||
begin
|
begin
|
||||||
handle_request event
|
handle_request event
|
||||||
rescue e
|
rescue e
|
||||||
@ -186,12 +213,12 @@ class AuthD::Service < IPC
|
|||||||
end
|
end
|
||||||
|
|
||||||
when LibIPC::EventType::MessageTx
|
when LibIPC::EventType::MessageTx
|
||||||
Baguette::Log.debug "Message sent to #{event.fd}" if @configuration.print_ipc_message_sent
|
Baguette::Log.debug "Message sent to #{event.fd}" if should_display? IPCMESSAGE::TX
|
||||||
|
|
||||||
when LibIPC::EventType::Connection
|
when LibIPC::EventType::Connection
|
||||||
Baguette::Log.debug "Connection from #{event.fd}" if @configuration.print_ipc_connection
|
Baguette::Log.debug "Connection from #{event.fd}" if should_display? IPCMESSAGE::CONNECTION
|
||||||
when LibIPC::EventType::Disconnection
|
when LibIPC::EventType::Disconnection
|
||||||
Baguette::Log.debug "Disconnection from #{event.fd}" if @configuration.print_ipc_disconnection
|
Baguette::Log.debug "Disconnection from #{event.fd}" if should_display? IPCMESSAGE::DISCONNECTION
|
||||||
@logged_users.delete event.fd
|
@logged_users.delete event.fd
|
||||||
else
|
else
|
||||||
Baguette::Log.error "Not implemented behavior for event: #{event}"
|
Baguette::Log.error "Not implemented behavior for event: #{event}"
|
||||||
|
Loading…
Reference in New Issue
Block a user