Delete RR.
This commit is contained in:
parent
2df5cbe3d9
commit
f60530750b
@ -67,6 +67,13 @@ class DNSManager::Client < IPC
|
|||||||
parse_message [ Response::Success ], read
|
parse_message [ Response::Success ], read
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Delete a RR.
|
||||||
|
def user_rr_delete(domain : String, rr : UInt32)
|
||||||
|
request = Request::DeleteRR.new domain, rr
|
||||||
|
send_now request
|
||||||
|
parse_message [ Response::Success ], read
|
||||||
|
end
|
||||||
|
|
||||||
# Get user domain list.
|
# Get user domain list.
|
||||||
def user_domain_list()
|
def user_domain_list()
|
||||||
request = Request::UserDomains.new
|
request = Request::UserDomains.new
|
||||||
|
@ -46,6 +46,7 @@ class Actions
|
|||||||
# Zone RR operations.
|
# Zone RR operations.
|
||||||
@the_call["user-rr-add-a"] = ->user_rr_add_a
|
@the_call["user-rr-add-a"] = ->user_rr_add_a
|
||||||
@the_call["user-rr-update-a"] = ->user_rr_update_a
|
@the_call["user-rr-update-a"] = ->user_rr_update_a
|
||||||
|
@the_call["user-rr-del"] = ->user_rr_del
|
||||||
|
|
||||||
@the_call["user-domain-list"] = ->user_domain_list
|
@the_call["user-domain-list"] = ->user_domain_list
|
||||||
end
|
end
|
||||||
@ -152,6 +153,13 @@ class Actions
|
|||||||
puts "error for user_rr_update_a: #{e.message}"
|
puts "error for user_rr_update_a: #{e.message}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def user_rr_del
|
||||||
|
domain, rrid = Context.args.not_nil!
|
||||||
|
pp! @dnsmanagerd.user_rr_delete domain, rrid.to_u32
|
||||||
|
rescue e
|
||||||
|
puts "error for user_rr_del: #{e.message}"
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -165,6 +165,13 @@ def parsing_cli(authd_config : Baguette::Configuration::Auth)
|
|||||||
unrecognized_args_to_context_args.call parser, 5, nil
|
unrecognized_args_to_context_args.call parser, 5, nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
parser.on("del", "Delete a RR.") do
|
||||||
|
Baguette::Log.info "delete a RR."
|
||||||
|
parser.banner = "COMMAND: user rr del <domain> <rrid>"
|
||||||
|
Context.command = "user-rr-del"
|
||||||
|
unrecognized_args_to_context_args.call parser, 2, nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -86,4 +86,19 @@ class DNSManager::Request
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
DNSManager.requests << UpdateRR
|
DNSManager.requests << UpdateRR
|
||||||
|
|
||||||
|
IPC::JSON.message DeleteRR, 16 do
|
||||||
|
property domain : String
|
||||||
|
property rrid : UInt32
|
||||||
|
|
||||||
|
def initialize(@domain, @rrid)
|
||||||
|
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.delete_rr user.uid, @domain, @rrid
|
||||||
|
end
|
||||||
|
end
|
||||||
|
DNSManager.requests << DeleteRR
|
||||||
end
|
end
|
||||||
|
@ -170,6 +170,37 @@ class DNSManager::Storage
|
|||||||
Response::Error.new "error while replacing a resource record in domain #{domain}"
|
Response::Error.new "error while replacing a resource record in domain #{domain}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def delete_rr(user_id : Int32, domain : String, rrid : UInt32) : 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 add -or update- zone #{domain}"
|
||||||
|
return Response::UnknownUser.new
|
||||||
|
end
|
||||||
|
|
||||||
|
# Zone must exist.
|
||||||
|
zone = zones_by_domain.get? domain
|
||||||
|
unless zone
|
||||||
|
return Response::InvalidZone.new ["Domain not found."]
|
||||||
|
end
|
||||||
|
|
||||||
|
# User must own the zone.
|
||||||
|
unless user_data.domains.includes? domain
|
||||||
|
Baguette::Log.warning "user #{user_id} doesn't own domain #{domain}"
|
||||||
|
return Response::NoOwnership.new
|
||||||
|
end
|
||||||
|
|
||||||
|
zone.resources.select! { |x| x.rrid != rrid }
|
||||||
|
|
||||||
|
# Update the zone.
|
||||||
|
zones_by_domain.update_or_create zone.domain, zone
|
||||||
|
|
||||||
|
Response::Success.new
|
||||||
|
rescue e
|
||||||
|
Baguette::Log.error "trying to replace a resource record in domain #{domain}: #{e}"
|
||||||
|
Response::Error.new "error while replacing a resource record in domain #{domain}"
|
||||||
|
end
|
||||||
|
|
||||||
def delete_domain(user_id : Int32, domain : String) : IPC::JSON
|
def delete_domain(user_id : Int32, domain : String) : IPC::JSON
|
||||||
# User must exist.
|
# User must exist.
|
||||||
user_data = user_data_by_uid.get? user_id.to_s
|
user_data = user_data_by_uid.get? user_id.to_s
|
||||||
|
Loading…
Reference in New Issue
Block a user