New/del domain + client API changes.
This commit is contained in:
parent
f0fdf75251
commit
a4ee0acf0e
9
Makefile
9
Makefile
@ -23,12 +23,15 @@ VERBOSITY ?= 4
|
|||||||
run-client-verbosity:
|
run-client-verbosity:
|
||||||
@$(LD_P) ./bin/dnsmanager-client admin maintenance verbosity $(VERBOSITY) $(LOGIN_OPT)
|
@$(LD_P) ./bin/dnsmanager-client admin maintenance verbosity $(VERBOSITY) $(LOGIN_OPT)
|
||||||
|
|
||||||
|
run-client-domain-add:
|
||||||
|
@$(LD_P) ./bin/dnsmanager-client user domain add $(DOMAIN) $(LOGIN_OPT)
|
||||||
|
|
||||||
|
run-client-domain-del:
|
||||||
|
@$(LD_P) ./bin/dnsmanager-client user domain del $(DOMAIN) $(LOGIN_OPT)
|
||||||
|
|
||||||
run-client-zone-add:
|
run-client-zone-add:
|
||||||
@$(LD_P) ./bin/dnsmanager-client user zone add $(DOMAIN).json $(LOGIN_OPT)
|
@$(LD_P) ./bin/dnsmanager-client user zone add $(DOMAIN).json $(LOGIN_OPT)
|
||||||
|
|
||||||
run-client-zone-del:
|
|
||||||
@$(LD_P) ./bin/dnsmanager-client user zone del $(DOMAIN) $(LOGIN_OPT)
|
|
||||||
|
|
||||||
RRID ?= 1
|
RRID ?= 1
|
||||||
NAME ?=
|
NAME ?=
|
||||||
TTL ?= 3600
|
TTL ?= 3600
|
||||||
|
@ -12,16 +12,6 @@ class DNSManager::Client < IPC
|
|||||||
@server_fd = fd
|
@server_fd = fd
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: parse_message should raise exception if response not anticipated
|
|
||||||
def parse_message(expected_messages, message)
|
|
||||||
em = Array(IPC::JSON.class).new
|
|
||||||
expected_messages.each do |e|
|
|
||||||
em << e
|
|
||||||
end
|
|
||||||
em << Response::Error
|
|
||||||
em.parse_ipc_json message
|
|
||||||
end
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Simple users.
|
# Simple users.
|
||||||
#
|
#
|
||||||
@ -32,16 +22,38 @@ class DNSManager::Client < IPC
|
|||||||
parse_message [ Response::Success ], read
|
parse_message [ Response::Success ], read
|
||||||
end
|
end
|
||||||
|
|
||||||
# Adding a full zone.
|
#
|
||||||
def user_zone_add(zone : Storage::Zone)
|
# Domain operations
|
||||||
request = Request::AddOrUpdateZone.new zone
|
#
|
||||||
|
|
||||||
|
# Add a domain.
|
||||||
|
def user_domain_add(domain : String)
|
||||||
|
request = Request::NewDomain.new domain
|
||||||
send_now request
|
send_now request
|
||||||
parse_message [ Response::Success ], read
|
parse_message [ Response::Success ], read
|
||||||
end
|
end
|
||||||
|
|
||||||
# Removing a zone.
|
# Remove a domain.
|
||||||
def user_zone_del(domain : String)
|
def user_domain_del(domain : String)
|
||||||
request = Request::DeleteZone.new domain
|
request = Request::DeleteDomain.new domain
|
||||||
|
send_now request
|
||||||
|
parse_message [ Response::Success ], read
|
||||||
|
end
|
||||||
|
|
||||||
|
# Get user domain list.
|
||||||
|
def user_domain_list()
|
||||||
|
request = Request::UserDomains.new
|
||||||
|
send_now request
|
||||||
|
parse_message [ Response::DomainList ], read
|
||||||
|
end
|
||||||
|
|
||||||
|
#
|
||||||
|
# Zone operations
|
||||||
|
#
|
||||||
|
|
||||||
|
# Add a full zone.
|
||||||
|
def user_zone_add(zone : Storage::Zone)
|
||||||
|
request = Request::AddOrUpdateZone.new zone
|
||||||
send_now request
|
send_now request
|
||||||
parse_message [ Response::Success ], read
|
parse_message [ Response::Success ], read
|
||||||
end
|
end
|
||||||
@ -53,6 +65,10 @@ class DNSManager::Client < IPC
|
|||||||
parse_message [ Response::Zone ], read
|
parse_message [ Response::Zone ], read
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#
|
||||||
|
# Resource Record operations
|
||||||
|
#
|
||||||
|
|
||||||
# Add a RR.
|
# Add a RR.
|
||||||
def user_rr_add(domain : String, rr : Storage::Zone::ResourceRecord)
|
def user_rr_add(domain : String, rr : Storage::Zone::ResourceRecord)
|
||||||
request = Request::AddRR.new domain, rr
|
request = Request::AddRR.new domain, rr
|
||||||
@ -74,15 +90,8 @@ 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 = Request::UserDomains.new
|
|
||||||
send_now request
|
|
||||||
parse_message [ Response::DomainList ], read
|
|
||||||
end
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Admin stuff.
|
# Admin stuff
|
||||||
#
|
#
|
||||||
|
|
||||||
def admin_maintenance(subject : Request::Maintenance::Subject, value : Int32? = nil)
|
def admin_maintenance(subject : Request::Maintenance::Subject, value : Int32? = nil)
|
||||||
@ -94,6 +103,10 @@ class DNSManager::Client < IPC
|
|||||||
parse_message [ Response::Success ], read
|
parse_message [ Response::Success ], read
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#
|
||||||
|
# Utils
|
||||||
|
#
|
||||||
|
|
||||||
def send_now(msg : IPC::JSON)
|
def send_now(msg : IPC::JSON)
|
||||||
m = IPCMessage::TypedMessage.new msg.type.to_u8, msg.to_json
|
m = IPCMessage::TypedMessage.new msg.type.to_u8, msg.to_json
|
||||||
write @server_fd, m
|
write @server_fd, m
|
||||||
@ -109,4 +122,14 @@ class DNSManager::Client < IPC
|
|||||||
m = IPCMessage::TypedMessage.deserialize slice
|
m = IPCMessage::TypedMessage.deserialize slice
|
||||||
m.not_nil!
|
m.not_nil!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# TODO: parse_message should raise exception if response not anticipated
|
||||||
|
def parse_message(expected_messages, message)
|
||||||
|
em = Array(IPC::JSON.class).new
|
||||||
|
expected_messages.each do |e|
|
||||||
|
em << e
|
||||||
|
end
|
||||||
|
em << Response::Error
|
||||||
|
em.parse_ipc_json message
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -35,17 +35,19 @@ class Actions
|
|||||||
# Maintenance.
|
# Maintenance.
|
||||||
@the_call["admin-maintenance"] = ->admin_maintenance
|
@the_call["admin-maintenance"] = ->admin_maintenance
|
||||||
|
|
||||||
|
# Domain operations.
|
||||||
|
@the_call["user-domain-add"] = ->user_domain_add
|
||||||
|
@the_call["user-domain-del"] = ->user_domain_del
|
||||||
|
@the_call["user-domain-list"] = ->user_domain_list
|
||||||
|
|
||||||
# Zone operations.
|
# Zone operations.
|
||||||
@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-get"] = ->user_zone_get
|
@the_call["user-zone-get"] = ->user_zone_get
|
||||||
|
|
||||||
# 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-rr-del"] = ->user_rr_del
|
||||||
|
|
||||||
@the_call["user-domain-list"] = ->user_domain_list
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def admin_maintenance
|
def admin_maintenance
|
||||||
@ -75,6 +77,30 @@ class Actions
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def user_domain_add
|
||||||
|
domains = Context.args.not_nil!
|
||||||
|
domains.each do |domain|
|
||||||
|
begin
|
||||||
|
pp! domain
|
||||||
|
pp! @dnsmanagerd.user_domain_add domain
|
||||||
|
rescue e
|
||||||
|
puts "error for user_domain_add: #{e.message}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def user_domain_del
|
||||||
|
domains = Context.args.not_nil!
|
||||||
|
domains.each do |domain|
|
||||||
|
begin
|
||||||
|
pp! domain
|
||||||
|
pp! @dnsmanagerd.user_domain_del domain
|
||||||
|
rescue e
|
||||||
|
puts "error for user_domain_del: #{e.message}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def user_zone_add
|
def user_zone_add
|
||||||
zones = read_zones
|
zones = read_zones
|
||||||
zones.each do |zone|
|
zones.each do |zone|
|
||||||
@ -87,18 +113,6 @@ class Actions
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def user_zone_del
|
|
||||||
domains = Context.args.not_nil!
|
|
||||||
domains.each do |domain|
|
|
||||||
begin
|
|
||||||
pp! domain
|
|
||||||
pp! @dnsmanagerd.user_zone_del domain
|
|
||||||
rescue e
|
|
||||||
puts "error for user_zone_del: #{e.message}"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def user_zone_get
|
def user_zone_get
|
||||||
domains = Context.args.not_nil!
|
domains = Context.args.not_nil!
|
||||||
domains.each do |domain|
|
domains.each do |domain|
|
||||||
|
@ -103,6 +103,31 @@ def parsing_cli(authd_config : Baguette::Configuration::Auth)
|
|||||||
# User section.
|
# User section.
|
||||||
parser.on "user", "Simple user operations." do
|
parser.on "user", "Simple user operations." do
|
||||||
parser.banner = "Operations as a simple user."
|
parser.banner = "Operations as a simple user."
|
||||||
|
|
||||||
|
# Domain.
|
||||||
|
parser.on("domain", "Domain operations.") do
|
||||||
|
parser.on("add", "Add a new domain.") do
|
||||||
|
Baguette::Log.info "add domain."
|
||||||
|
Context.command = "user-domain-add"
|
||||||
|
parser.banner = "COMMAND: user domain add domain [domain...]"
|
||||||
|
unrecognized_args_to_context_args.call parser, nil, 1
|
||||||
|
end
|
||||||
|
|
||||||
|
parser.on("del", "Delete a domain.") do
|
||||||
|
Baguette::Log.info "del domain."
|
||||||
|
Context.command = "user-domain-del"
|
||||||
|
parser.banner = "COMMAND: user domain 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 domain list"
|
||||||
|
unrecognized_args_to_context_args.call parser, 0, nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Zone.
|
# Zone.
|
||||||
parser.on("zone", "Zone operations.") do
|
parser.on("zone", "Zone operations.") do
|
||||||
parser.on("add", "Add new zone.") do
|
parser.on("add", "Add new zone.") do
|
||||||
@ -112,9 +137,9 @@ def parsing_cli(authd_config : Baguette::Configuration::Auth)
|
|||||||
unrecognized_args_to_context_args.call parser, nil, 1
|
unrecognized_args_to_context_args.call parser, nil, 1
|
||||||
end
|
end
|
||||||
|
|
||||||
parser.on("del", "Delete a zone.") do
|
parser.on("del", "Delete a zone (alias to domain del).") do
|
||||||
Baguette::Log.info "del zone."
|
Baguette::Log.info "del zone."
|
||||||
Context.command = "user-zone-del"
|
Context.command = "user-domain-del"
|
||||||
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
|
||||||
@ -126,8 +151,8 @@ def parsing_cli(authd_config : Baguette::Configuration::Auth)
|
|||||||
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
|
parser.on("list", "List all domains (alias to domain list).") do
|
||||||
Baguette::Log.info "List domains."
|
Baguette::Log.info "list domains."
|
||||||
Context.command = "user-domain-list"
|
Context.command = "user-domain-list"
|
||||||
parser.banner = "COMMAND: user zone list"
|
parser.banner = "COMMAND: user zone list"
|
||||||
unrecognized_args_to_context_args.call parser, 0, nil
|
unrecognized_args_to_context_args.call parser, 0, nil
|
||||||
|
@ -17,7 +17,21 @@ class DNSManager::Request
|
|||||||
end
|
end
|
||||||
DNSManager.requests << NewDomain
|
DNSManager.requests << NewDomain
|
||||||
|
|
||||||
IPC::JSON.message AddOrUpdateZone, 10 do
|
IPC::JSON.message DeleteDomain, 10 do
|
||||||
|
property domain : String
|
||||||
|
|
||||||
|
def initialize(@domain)
|
||||||
|
end
|
||||||
|
|
||||||
|
def handle(dnsmanagerd : DNSManager::Service, event : IPC::Event) : IPC::JSON
|
||||||
|
user = dnsmanagerd.get_logged_user event
|
||||||
|
return Response::ErrorUserNotLogged.new unless user
|
||||||
|
dnsmanagerd.storage.delete_domain user.uid, @domain
|
||||||
|
end
|
||||||
|
end
|
||||||
|
DNSManager.requests << DeleteDomain
|
||||||
|
|
||||||
|
IPC::JSON.message AddOrUpdateZone, 11 do
|
||||||
property zone : DNSManager::Storage::Zone
|
property zone : DNSManager::Storage::Zone
|
||||||
|
|
||||||
def initialize(@zone)
|
def initialize(@zone)
|
||||||
@ -31,20 +45,6 @@ class DNSManager::Request
|
|||||||
end
|
end
|
||||||
DNSManager.requests << AddOrUpdateZone
|
DNSManager.requests << AddOrUpdateZone
|
||||||
|
|
||||||
IPC::JSON.message DeleteZone, 11 do
|
|
||||||
property domain : String
|
|
||||||
|
|
||||||
def initialize(@domain)
|
|
||||||
end
|
|
||||||
|
|
||||||
def handle(dnsmanagerd : DNSManager::Service, event : IPC::Event) : IPC::JSON
|
|
||||||
user = dnsmanagerd.get_logged_user event
|
|
||||||
return Response::ErrorUserNotLogged.new unless user
|
|
||||||
dnsmanagerd.storage.delete_domain user.uid, @domain
|
|
||||||
end
|
|
||||||
end
|
|
||||||
DNSManager.requests << DeleteZone
|
|
||||||
|
|
||||||
IPC::JSON.message GetZone, 12 do
|
IPC::JSON.message GetZone, 12 do
|
||||||
property domain : String
|
property domain : String
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user