List all user domains.

This commit is contained in:
Philippe Pittoli 2023-05-07 20:50:56 +02:00
parent 22d110d45d
commit 1df35ad4c3
6 changed files with 61 additions and 0 deletions

View File

@ -46,6 +46,13 @@ class DNSManager::Client < IPC
parse_message [ Response::Success ], read parse_message [ Response::Success ], read
end 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. # Admin stuff.
# #

View File

@ -39,6 +39,7 @@ class Actions
@the_call["admin-maintenance"] = ->admin_maintenance @the_call["admin-maintenance"] = ->admin_maintenance
@the_call["user-zone-add"] = ->user_zone_add @the_call["user-zone-add"] = ->user_zone_add
@the_call["user-zone-del"] = ->user_zone_del @the_call["user-zone-del"] = ->user_zone_del
@the_call["user-domain-list"] = ->user_domain_list
end end
def admin_maintenance def admin_maintenance
@ -92,6 +93,20 @@ class Actions
end end
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 end
def main def main

View File

@ -127,6 +127,13 @@ def parsing_cli(authd_config : Baguette::Configuration::Auth)
parser.banner = "COMMAND: user zone del domain [domain...]" parser.banner = "COMMAND: user zone del domain [domain...]"
unrecognized_args_to_context_args.call parser, nil, 1 unrecognized_args_to_context_args.call parser, nil, 1
end 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
end end

View File

@ -30,4 +30,16 @@ class DNSManager::Request
end end
end end
DNSManager.requests << DeleteZone 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 end

View File

@ -14,5 +14,12 @@ class DNSManager::Response
end end
end end
DNSManager.responses << DomainChanged DNSManager.responses << DomainChanged
IPC::JSON.message DomainList, 12 do
property domains : Array(String)
def initialize(@domains)
end
end
DNSManager.responses << DomainList
end end

View File

@ -121,6 +121,19 @@ class DNSManager::Storage
Response::Error.new "error while deleting the domain #{domain}" Response::Error.new "error while deleting the domain #{domain}"
end 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 end
require "./storage/*" require "./storage/*"