Fix logging, add zone file generation request.
This commit is contained in:
parent
0a03977a5e
commit
8bec7eb33c
@ -19,7 +19,7 @@ class DNSManager::Client < IPC
|
||||
def login(token : String)
|
||||
request = Request::Login.new token
|
||||
send_now request
|
||||
parse_message [ Response::Success ], read
|
||||
parse_message [ Response::Logged ], read
|
||||
end
|
||||
|
||||
#
|
||||
@ -94,11 +94,18 @@ class DNSManager::Client < IPC
|
||||
# Admin stuff
|
||||
#
|
||||
|
||||
def admin_maintenance(subject : Request::Maintenance::Subject, value : Int32? = nil)
|
||||
def admin_maintenance(subject : Request::Maintenance::Subject,
|
||||
int : Int32? = nil,
|
||||
string : String? = nil)
|
||||
request = Request::Maintenance.new(subject)
|
||||
if value
|
||||
request.value = value
|
||||
end
|
||||
request.int = int if int
|
||||
request.string = string if string
|
||||
send_now request
|
||||
parse_message [ Response::Success ], read
|
||||
end
|
||||
|
||||
def generate_zonefile(domain : String)
|
||||
request = Request::GenerateZoneFile.new(domain)
|
||||
send_now request
|
||||
parse_message [ Response::Success ], read
|
||||
end
|
||||
@ -123,7 +130,7 @@ class DNSManager::Client < IPC
|
||||
m.not_nil!
|
||||
end
|
||||
|
||||
# TODO: parse_message should raise exception if response not anticipated
|
||||
# TODO: should raise exception if response not anticipated
|
||||
def parse_message(expected_messages, message)
|
||||
em = Array(IPC::JSON.class).new
|
||||
expected_messages.each do |e|
|
||||
|
@ -34,6 +34,7 @@ class Actions
|
||||
|
||||
# Maintenance.
|
||||
@the_call["admin-maintenance"] = ->admin_maintenance
|
||||
@the_call["admin-generate-zonefile"] = ->admin_generate_zonefile
|
||||
|
||||
# Domain operations.
|
||||
@the_call["user-domain-add"] = ->user_domain_add
|
||||
@ -63,11 +64,11 @@ class Actions
|
||||
end
|
||||
|
||||
if past_is_verbosity
|
||||
sub = DNSManager::Request::Maintenance::Subject::Verbosity
|
||||
value = subject.to_i
|
||||
@dnsmanagerd.admin_maintenance sub, value
|
||||
sub = DNSManager::Request::Maintenance::Subject::Verbosity
|
||||
int = subject.to_i
|
||||
@dnsmanagerd.admin_maintenance sub, int
|
||||
else
|
||||
sub = DNSManager::Request::Maintenance::Subject.parse(subject)
|
||||
sub = DNSManager::Request::Maintenance::Subject.parse(subject)
|
||||
pp! sub
|
||||
pp! @dnsmanagerd.admin_maintenance sub
|
||||
end
|
||||
@ -77,6 +78,18 @@ class Actions
|
||||
end
|
||||
end
|
||||
|
||||
def admin_generate_zonefile
|
||||
domains = Context.args.not_nil!
|
||||
domains.each do |domain|
|
||||
begin
|
||||
pp! domain
|
||||
pp! @dnsmanagerd.generate_zonefile domain
|
||||
rescue e
|
||||
puts "error for user_domain_add: #{e.message}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def user_domain_add
|
||||
domains = Context.args.not_nil!
|
||||
domains.each do |domain|
|
||||
@ -220,8 +233,21 @@ def main
|
||||
# Authd authentication, get the token and quit right away.
|
||||
token = authd_get_token login: login, pass: pass
|
||||
# Then push the token to the dnsmanager daemon.
|
||||
dnsmanagerd.login token
|
||||
Baguette::Log.info "logged."
|
||||
logged_message = dnsmanagerd.login token
|
||||
case logged_message
|
||||
when DNSManager::Response::Logged
|
||||
Baguette::Log.info "logged to dnsmanagerd"
|
||||
Baguette::Log.debug "from logging message, accepted domains:"
|
||||
logged_message.accepted_domains.each do |d|
|
||||
Baguette::Log.debug "- #{d}"
|
||||
end
|
||||
Baguette::Log.debug "from logging message, owned domains:"
|
||||
logged_message.my_domains.each do |d|
|
||||
Baguette::Log.debug "- #{d}"
|
||||
end
|
||||
else
|
||||
Baguette::Log.info "not logged to dnsmanagerd?"
|
||||
end
|
||||
end
|
||||
|
||||
actions = Actions.new dnsmanagerd, config
|
||||
|
@ -98,6 +98,14 @@ def parsing_cli(authd_config : Baguette::Configuration::Auth)
|
||||
unrecognized_args_to_context_args.call parser, nil, 1
|
||||
end
|
||||
|
||||
# Generate a zone file.
|
||||
parser.on("genzone", "Generate a zone file.") do
|
||||
Baguette::Log.info "generate a zone file on the server."
|
||||
Context.command = "admin-generate-zonefile"
|
||||
parser.banner = "COMMAND: admin genzone domain [domain…]"
|
||||
unrecognized_args_to_context_args.call parser, nil, 1
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# User section.
|
||||
|
Loading…
Reference in New Issue
Block a user