Enable the client to read the configuration (no more mandatory CLI auth).
This commit is contained in:
parent
ebcedc44ce
commit
8c4e64d75b
1 changed files with 40 additions and 2 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
require "baguette-crystal-base"
|
||||||
require "option_parser"
|
require "option_parser"
|
||||||
require "yaml"
|
require "yaml"
|
||||||
require "./authd.cr"
|
require "./authd.cr"
|
||||||
|
|
@ -305,6 +306,26 @@ def main
|
||||||
# Authd connection.
|
# Authd connection.
|
||||||
authd = AuthD::Client.new
|
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
|
if login = Context.authd_login
|
||||||
pass = if p = Context.authd_pass
|
pass = if p = Context.authd_pass
|
||||||
p
|
p
|
||||||
|
|
@ -317,11 +338,28 @@ def main
|
||||||
case response
|
case response
|
||||||
when Response::Login
|
when Response::Login
|
||||||
uid = response.uid
|
uid = response.uid
|
||||||
token = response.token
|
#token = response.token
|
||||||
Baguette::Log.info "Authenticated as #{login} #{uid}, token: #{token}"
|
Baguette::Log.info "Authenticated as #{login} #{uid}"
|
||||||
else
|
else
|
||||||
raise "Cannot authenticate to authd with login #{login}: #{response}."
|
raise "Cannot authenticate to authd with login #{login}: #{response}."
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
actions = Actions.new authd
|
actions = Actions.new authd
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue