From 925a456de7b83e8292d538995676b07d0b8528f5 Mon Sep 17 00:00:00 2001 From: Philippe PITTOLI Date: Sat, 8 Jun 2024 22:43:43 +0200 Subject: [PATCH] Migration script: first draft. --- src/client/main.cr | 21 +++++++++++++++++++++ src/client/parser.cr | 7 +++++++ 2 files changed, 28 insertions(+) diff --git a/src/client/main.cr b/src/client/main.cr index f0bcf59..b5c9496 100644 --- a/src/client/main.cr +++ b/src/client/main.cr @@ -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 domain1 domain2 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 diff --git a/src/client/parser.cr b/src/client/parser.cr index 31f8df5..5a8953f 100644 --- a/src/client/parser.cr +++ b/src/client/parser.cr @@ -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.