List all user domains.
parent
22d110d45d
commit
1df35ad4c3
|
@ -46,6 +46,13 @@ class DNSManager::Client < IPC
|
|||
parse_message [ Response::Success ], read
|
||||
end
|
||||
|
||||
# Get user domain list.
|
||||
def user_domain_list()
|
||||
request = DNSManager::Request::UserDomains.new
|
||||
send_now request
|
||||
parse_message [ Response::DomainList ], read
|
||||
end
|
||||
|
||||
#
|
||||
# Admin stuff.
|
||||
#
|
||||
|
|
|
@ -39,6 +39,7 @@ class Actions
|
|||
@the_call["admin-maintenance"] = ->admin_maintenance
|
||||
@the_call["user-zone-add"] = ->user_zone_add
|
||||
@the_call["user-zone-del"] = ->user_zone_del
|
||||
@the_call["user-domain-list"] = ->user_domain_list
|
||||
end
|
||||
|
||||
def admin_maintenance
|
||||
|
@ -92,6 +93,20 @@ class Actions
|
|||
end
|
||||
end
|
||||
|
||||
def user_domain_list
|
||||
response = @dnsmanagerd.user_domain_list
|
||||
case response
|
||||
when DNSManager::Response::DomainList
|
||||
response.domains.each do |domain|
|
||||
puts "- #{domain}"
|
||||
end
|
||||
else
|
||||
pp! response
|
||||
end
|
||||
rescue e
|
||||
puts "error for user_zone_del: #{e.message}"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def main
|
||||
|
|
|
@ -127,6 +127,13 @@ def parsing_cli(authd_config : Baguette::Configuration::Auth)
|
|||
parser.banner = "COMMAND: user zone del domain [domain...]"
|
||||
unrecognized_args_to_context_args.call parser, nil, 1
|
||||
end
|
||||
|
||||
parser.on("list", "List all domains.") do
|
||||
Baguette::Log.info "List domains."
|
||||
Context.command = "user-domain-list"
|
||||
parser.banner = "COMMAND: user zone list"
|
||||
unrecognized_args_to_context_args.call parser, 0, nil
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -30,4 +30,16 @@ class DNSManager::Request
|
|||
end
|
||||
end
|
||||
DNSManager.requests << DeleteZone
|
||||
|
||||
IPC::JSON.message UserDomains, 12 do
|
||||
def initialize()
|
||||
end
|
||||
|
||||
def handle(dnsmanagerd : DNSManager::Service, event : IPC::Event) : IPC::JSON
|
||||
user = dnsmanagerd.get_logged_user event
|
||||
raise NotLoggedException.new if user.nil?
|
||||
dnsmanagerd.storage.user_domains user.uid
|
||||
end
|
||||
end
|
||||
DNSManager.requests << UserDomains
|
||||
end
|
||||
|
|
|
@ -14,5 +14,12 @@ class DNSManager::Response
|
|||
end
|
||||
end
|
||||
DNSManager.responses << DomainChanged
|
||||
|
||||
IPC::JSON.message DomainList, 12 do
|
||||
property domains : Array(String)
|
||||
def initialize(@domains)
|
||||
end
|
||||
end
|
||||
DNSManager.responses << DomainList
|
||||
end
|
||||
|
||||
|
|
|
@ -121,6 +121,19 @@ class DNSManager::Storage
|
|||
Response::Error.new "error while deleting the domain #{domain}"
|
||||
end
|
||||
|
||||
def user_domains(user_id : Int32) : IPC::JSON
|
||||
# User must exist.
|
||||
user_data = user_data_by_uid.get? user_id.to_s
|
||||
unless user_data
|
||||
Baguette::Log.warning "unknown user #{user_id} tries to list its domains"
|
||||
return Response::UnknownUser.new
|
||||
end
|
||||
|
||||
Response::DomainList.new user_data.domains
|
||||
rescue e
|
||||
Baguette::Log.error "while listing all user #{user_id} domains: #{e}"
|
||||
Response::Error.new "error while listing domains"
|
||||
end
|
||||
end
|
||||
|
||||
require "./storage/*"
|
||||
|
|
Loading…
Reference in New Issue