Migration script: done.

This commit is contained in:
Philippe PITTOLI 2024-06-08 20:35:41 +02:00
parent 111adae98f
commit ca4cb9e231
3 changed files with 36 additions and 0 deletions

View File

@ -52,6 +52,10 @@ get-user:
migrate-user: migrate-user:
./bin/authc user migrate $(NAME) $(PASSWORD_HASH) $(LOGIN_OPT) ./bin/authc user migrate $(NAME) $(PASSWORD_HASH) $(LOGIN_OPT)
USER_DB ?= user-db.txt
migrate-all-users:
./bin/authc migration-script $(USER_DB) $(LOGIN_OPT)
SERVICE ?= 'auth' SERVICE ?= 'auth'
RESOURCE ?= '*' RESOURCE ?= '*'
UID ?= 1000 UID ?= 1000

View File

@ -79,6 +79,17 @@ parser = OptionParser.new do |parser|
unrecognized_args_to_context_args.call parser, 2 unrecognized_args_to_context_args.call parser, 2
end end
parser.on "migration-script", "Adding a batch of users from old code base." do
parser.banner = "usage: migration-script user-db.txt"
Baguette::Log.info "Adding a batch of users."
Context.command = "migration-script"
opt_authd_login.call parser
opt_profile.call parser
opt_help.call parser
# user-db.txt
unrecognized_args_to_context_args.call parser, 1
end
parser.on "user", "Operations on users." do parser.on "user", "Operations on users." do
parser.banner = "Usage: user [add | mod | delete | validate | search | get | recover | register ]" parser.banner = "Usage: user [add | mod | delete | validate | search | get | recover | register ]"

View File

@ -63,6 +63,7 @@ class Actions
# Require admin privileges. # Require admin privileges.
@the_call["user-add"] = ->user_add @the_call["user-add"] = ->user_add
@the_call["user-migrate"] = ->user_migrate @the_call["user-migrate"] = ->user_migrate
@the_call["migration-script"] = ->migration_script
@the_call["user-mod"] = ->user_mod @the_call["user-mod"] = ->user_mod
@the_call["permission-set"] = ->permission_set @the_call["permission-set"] = ->permission_set
@ -99,6 +100,26 @@ class Actions
puts "error: #{e.message}" puts "error: #{e.message}"
end end
# Migrate a batch of users from dnsmanager v1.
#
# Usage: authc migration-script user-db.txt
#
# user-db.txt should be formated as "login <TAB> old-hash".
def migration_script
args = Context.args.not_nil!
filename = args[0]
profile = Context.user_profile
File.each_line(filename) do |line|
login, password_hash_brkn = line.split("\t")
Baguette::Log.info "adding user '#{login}', hash '#{password_hash_brkn}'"
pp! authd.migrate_user login, password_hash_brkn
end
rescue e : AuthD::Exception
puts "error: #{e.message}"
end
def user_registration def user_registration
args = Context.args.not_nil! args = Context.args.not_nil!
login, email = args[0..1] login, email = args[0..1]