Migration script: first draft.

This commit is contained in:
Philippe PITTOLI 2024-06-08 22:43:43 +02:00
parent b53b31b584
commit 925a456de7
2 changed files with 28 additions and 0 deletions

View File

@ -29,6 +29,7 @@ class Actions
# Maintenance.
@the_call["admin-maintenance"] = ->admin_maintenance
@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
# Domain operations.
@ -86,6 +87,26 @@ class Actions
end
end
# Migration script.
#
# Usage: dnsmanager-client admin migration-script user-db.txt
#
# user-db.txt should be formated as: login <TAB> domain1 <TAB> domain2 <TAB> domain3 (etc.)
def admin_migration_script
filename = Context.args.not_nil!.[0]
File.each_line(filename) do |line|
data = line.split "\t"
login = data.shift
begin
Baguette::Log.info "migrating login #{login}, domains: #{data.join(',')}"
# TODO
#pp! @dnsmanagerd.migration
rescue e
puts "error for generate_zonefile: #{e.message}"
end
end
end
def admin_generate_all_zonefiles
pp! @dnsmanagerd.generate_all_zonefiles
rescue e

View File

@ -116,6 +116,13 @@ def parsing_cli(authd_config : Baguette::Configuration::Auth)
unrecognized_args_to_context_args.call parser, 0, nil
end
# Migration script.
parser.on("migration-script", "Migrate domains from dnsmanager v1.") do
Baguette::Log.info "migration script, provide domains to users."
Context.command = "admin-migration-script"
parser.banner = "COMMAND: admin migration-script user-db.txt"
unrecognized_args_to_context_args.call parser, 1, nil
end
end
# User section.