Enable the client to read the configuration (no more mandatory CLI auth).

This commit is contained in:
Philippe Pittoli 2025-11-23 17:54:56 +01:00
parent ebcedc44ce
commit 8c4e64d75b

View file

@ -1,3 +1,4 @@
require "baguette-crystal-base"
require "option_parser"
require "yaml"
require "./authd.cr"
@ -305,6 +306,26 @@ def main
# Authd connection.
authd = AuthD::Client.new
# Read configuration.
simulation, no_configuration, configuration_file = Baguette::Configuration.option_parser
# Authd configuration.
authentication_config = if no_configuration
Baguette::Log.info "do not load a configuration file."
Baguette::Configuration::Auth.new
else
# Configuration file is for dnsmanagerd.
Baguette::Configuration::Auth.get || Baguette::Configuration::Auth.new
end
# FIXME I guess: why isn't this working?
#Baguette::Configuration.verbosity = authentication_config.verbosity
if key_file = authentication_config.secret_key_file
authentication_config.secret_key = File.read(key_file).chomp
end
# TODO: when I have the time, clean up this redundant piece of code. In the meantime, it works.
if login = Context.authd_login
pass = if p = Context.authd_pass
p
@ -317,11 +338,28 @@ def main
case response
when Response::Login
uid = response.uid
token = response.token
Baguette::Log.info "Authenticated as #{login} #{uid}, token: #{token}"
#token = response.token
Baguette::Log.info "Authenticated as #{login} #{uid}"
else
raise "Cannot authenticate to authd with login #{login}: #{response}."
end
else
Baguette::Log.info "no authd login from CLI."
if authentication_config.login.nil? || authentication_config.pass.nil?
Baguette::Log.info "no authd login from configuration either."
else
login = authentication_config.login.not_nil!
pass = authentication_config.pass.not_nil!
response = authd.login? login, pass
case response
when Response::Login
uid = response.uid
#token = response.token
Baguette::Log.info "Authenticated as #{login} #{uid}"
else
raise "Cannot authenticate to authd with login #{login}: #{response}."
end
end
end
actions = Actions.new authd