From 5147719ecb44913c68e254a53d6b08047feaceac Mon Sep 17 00:00:00 2001 From: Philippe Pittoli Date: Wed, 27 Nov 2024 11:58:05 +0100 Subject: [PATCH] Remove and create a domain. --- src/client/lib/dnsmanager-client.cr | 14 +++++++++++++- src/client/main.cr | 8 ++++++++ src/client/parser.cr | 8 ++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/client/lib/dnsmanager-client.cr b/src/client/lib/dnsmanager-client.cr index fee0547..a07d514 100644 --- a/src/client/lib/dnsmanager-client.cr +++ b/src/client/lib/dnsmanager-client.cr @@ -74,7 +74,7 @@ class DNSManager::Client < IPC def user_domain_del(domain : String) request = Request::DeleteDomain.new domain send_now request - parse_message [ Response::Success ], read + parse_message [ Response::DomainDeleted ], read end # Get user domain list. @@ -109,6 +109,18 @@ class DNSManager::Client < IPC parse_message [ Response::GeneratedZone ], read end + # Provide a domain to a user. + def provide_domain(login : String, domain : String) + request = Request::Migration.new login, domain + send_now request + parse_message [ Response::DomainAdded, + Response::DomainAlreadyExists, + Response::InvalidDomainName, + Response::UnacceptableDomain, + Response::UnknownUser + ], read + end + # # Resource Record operations # diff --git a/src/client/main.cr b/src/client/main.cr index eea5bae..65a64fa 100644 --- a/src/client/main.cr +++ b/src/client/main.cr @@ -31,6 +31,7 @@ class Actions @the_call["admin-generate-zonefile"] = ->admin_generate_zonefile @the_call["admin-migration-script"] = ->admin_migration_script @the_call["admin-generate-all-zonefiles"] = ->admin_generate_all_zonefiles + @the_call["admin-provide-domain"] = ->admin_provide_domain # Domain operations. @the_call["user-domain-add"] = ->user_domain_add @@ -147,6 +148,13 @@ class Actions puts "error for generate_all_zonefiles: #{e.message}" end + def admin_provide_domain + login, domain = Context.args.not_nil! + pp! @dnsmanagerd.provide_domain login, domain + rescue e + puts "error for provide_domain: #{e.message}" + end + def user_domain_add domains = Context.args.not_nil! domains.each do |domain| diff --git a/src/client/parser.cr b/src/client/parser.cr index 5a8953f..705e8a3 100644 --- a/src/client/parser.cr +++ b/src/client/parser.cr @@ -116,6 +116,14 @@ def parsing_cli(authd_config : Baguette::Configuration::Auth) unrecognized_args_to_context_args.call parser, 0, nil end + # Provide a domain to someone. + parser.on("provide-domain", "Create a domain for someone.") do + Baguette::Log.info "creating a domain for someone." + Context.command = "admin-provide-domain" + parser.banner = "COMMAND: admin provide-domain " + unrecognized_args_to_context_args.call parser, 2, nil + end + # Migration script. parser.on("migration-script", "Migrate domains from dnsmanager v1.") do Baguette::Log.info "migration script, provide domains to users."