Update RR is working.
This commit is contained in:
parent
8528f74fae
commit
2df5cbe3d9
@ -60,6 +60,13 @@ class DNSManager::Client < IPC
|
||||
parse_message [ Response::Success ], read
|
||||
end
|
||||
|
||||
# Update a RR.
|
||||
def user_rr_update(domain : String, rr : Storage::Zone::ResourceRecord)
|
||||
request = Request::UpdateRR.new domain, rr
|
||||
send_now request
|
||||
parse_message [ Response::Success ], read
|
||||
end
|
||||
|
||||
# Get user domain list.
|
||||
def user_domain_list()
|
||||
request = Request::UserDomains.new
|
||||
|
@ -45,6 +45,7 @@ class Actions
|
||||
|
||||
# Zone RR operations.
|
||||
@the_call["user-rr-add-a"] = ->user_rr_add_a
|
||||
@the_call["user-rr-update-a"] = ->user_rr_update_a
|
||||
|
||||
@the_call["user-domain-list"] = ->user_domain_list
|
||||
end
|
||||
@ -136,14 +137,22 @@ class Actions
|
||||
|
||||
def user_rr_add_a
|
||||
domain, name, ttl, target = Context.args.not_nil!
|
||||
begin
|
||||
rr = DNSManager::Storage::Zone::A.new name, ttl.to_u32, target
|
||||
pp! @dnsmanagerd.user_rr_add domain, rr
|
||||
rescue e
|
||||
puts "error for user_rr_add_a: #{e.message}"
|
||||
end
|
||||
|
||||
def user_rr_update_a
|
||||
domain, rrid, name, ttl, target = Context.args.not_nil!
|
||||
rr = DNSManager::Storage::Zone::A.new name, ttl.to_u32, target
|
||||
rr.rrid = rrid.to_u32
|
||||
pp! @dnsmanagerd.user_rr_update domain, rr
|
||||
rescue e
|
||||
puts "error for user_rr_update_a: #{e.message}"
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
def main
|
||||
|
@ -154,6 +154,17 @@ def parsing_cli(authd_config : Baguette::Configuration::Auth)
|
||||
unrecognized_args_to_context_args.call parser, 4, nil
|
||||
end
|
||||
end
|
||||
|
||||
parser.on("update", "Update a RR.") do
|
||||
Baguette::Log.info "Update a RR."
|
||||
parser.banner = "COMMAND: user rr update [A|AAAA|CNAME|MX|SRV|TXT|NS|SOA]"
|
||||
parser.on("A", "Update an A RR.") do
|
||||
Baguette::Log.info "update an A RR."
|
||||
Context.command = "user-rr-update-a"
|
||||
parser.banner = "COMMAND: user rr update A <domain> <rrid> <NAME> <TTL> <TARGET>"
|
||||
unrecognized_args_to_context_args.call parser, 5, nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -112,6 +112,14 @@ class DNSManager::Storage
|
||||
return Response::NoOwnership.new
|
||||
end
|
||||
|
||||
# Test RR validity.
|
||||
rr.get_errors.tap do |errors|
|
||||
unless errors.empty?
|
||||
Baguette::Log.warning "Add RR with errors: #{errors}"
|
||||
return Response::InvalidZone.new errors
|
||||
end
|
||||
end
|
||||
|
||||
zone << rr
|
||||
|
||||
# Update the zone.
|
||||
@ -143,7 +151,15 @@ class DNSManager::Storage
|
||||
return Response::NoOwnership.new
|
||||
end
|
||||
|
||||
zone.resources.map { |x| x.rrid == rr.rrid ? rr : x }
|
||||
# Test RR validity.
|
||||
rr.get_errors.tap do |errors|
|
||||
unless errors.empty?
|
||||
Baguette::Log.warning "update RR with errors: #{errors}"
|
||||
return Response::InvalidZone.new errors
|
||||
end
|
||||
end
|
||||
|
||||
zone.resources = zone.resources.map { |x| x.rrid == rr.rrid ? rr : x }
|
||||
|
||||
# Update the zone.
|
||||
zones_by_domain.update_or_create zone.domain, zone
|
||||
|
Loading…
Reference in New Issue
Block a user