Client: add zone operations (add and del).

This commit is contained in:
Philippe Pittoli 2023-05-07 04:09:44 +02:00
parent 0ca5ec6f78
commit 41828a3f91
2 changed files with 31 additions and 6 deletions

View File

@ -37,8 +37,8 @@ class Actions
# Maintenance # Maintenance
@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
end end
def admin_maintenance def admin_maintenance
@ -100,7 +100,7 @@ def main
# Authd configuration. # Authd configuration.
authd_config = if no_configuration authd_config = if no_configuration
Baguette::Log.info "do not load a configuration file." Baguette::Log.info "do not load a configuration file (authd)."
Baguette::Configuration::Auth.new Baguette::Configuration::Auth.new
else else
# Configuration file is for dnsmanagerd. # Configuration file is for dnsmanagerd.
@ -112,7 +112,7 @@ def main
# Authd configuration. # Authd configuration.
config = if no_configuration config = if no_configuration
Baguette::Log.info "do not load a configuration file." Baguette::Log.info "do not load a configuration file (dnsmanagerd)."
Baguette::Configuration::DNSManager.new Baguette::Configuration::DNSManager.new
else else
# Configuration file is for dnsmanagerd. # Configuration file is for dnsmanagerd.
@ -137,12 +137,14 @@ def main
# Authd authentication, get the token and quit right away. # Authd authentication, get the token and quit right away.
# If login == pass == "undef": do not even try. # If login == pass == "undef": do not even try.
if authd_config.login.nil? || authd_config.pass.nil? if authd_config.login.nil? || authd_config.pass.nil?
Baguette::Log.info "no authd login" Baguette::Log.info "no authd login."
else else
Baguette::Log.info "authd login..."
login = authd_config.login.not_nil! login = authd_config.login.not_nil!
pass = authd_config.pass.not_nil! pass = authd_config.pass.not_nil!
token = authd_get_token login: login, pass: pass token = authd_get_token login: login, pass: pass
dnsmanagerd.login token dnsmanagerd.login token
Baguette::Log.info "logged."
end end
#authd = AuthD::Client.new #authd = AuthD::Client.new

View File

@ -95,12 +95,13 @@ def parsing_cli(authd_config : Baguette::Configuration::Auth)
# Admin section. # Admin section.
parser.on "admin", "Admin operations." do parser.on "admin", "Admin operations." do
parser.banner = "Admin operations (requires secret via -k)."
# All admin operations require the shared key. # All admin operations require the shared key.
opt_authd_admin.call parser, authd_config opt_authd_admin.call parser, authd_config
# Maintenance. # Maintenance.
parser.on("maintenance", "Maintenance operation of the website.") do parser.on("maintenance", "Maintenance operation of the website.") do
Baguette::Log.info "Maintenance operation of the website." Baguette::Log.info "maintenance operation of the website."
Context.command = "admin-maintenance" Context.command = "admin-maintenance"
parser.banner = "COMMAND: admin maintenance subject [value]" parser.banner = "COMMAND: admin maintenance subject [value]"
unrecognized_args_to_context_args.call parser, nil, 1 unrecognized_args_to_context_args.call parser, nil, 1
@ -108,6 +109,28 @@ def parsing_cli(authd_config : Baguette::Configuration::Auth)
end end
# User section.
parser.on "user", "Simple user operations." do
parser.banner = "Operations as a simple user."
# Zone.
parser.on("zone", "Zone operations.") do
parser.on("add", "Add new zone.") do
Baguette::Log.info "add zone."
Context.command = "user-zone-add"
parser.banner = "COMMAND: user zone add <file> [<file>...]"
unrecognized_args_to_context_args.call parser, nil, 1
end
parser.on("del", "Delete a zone.") do
Baguette::Log.info "del zone."
Context.command = "user-zone-del"
parser.banner = "COMMAND: user zone del domain [domain...]"
unrecognized_args_to_context_args.call parser, nil, 1
end
end
end
opt_help.call parser opt_help.call parser
end end