Migration script: done.
This commit is contained in:
parent
111adae98f
commit
ca4cb9e231
4
makefile
4
makefile
@ -52,6 +52,10 @@ get-user:
|
||||
migrate-user:
|
||||
./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'
|
||||
RESOURCE ?= '*'
|
||||
UID ?= 1000
|
||||
|
@ -79,6 +79,17 @@ parser = OptionParser.new do |parser|
|
||||
unrecognized_args_to_context_args.call parser, 2
|
||||
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.banner = "Usage: user [add | mod | delete | validate | search | get | recover | register ]"
|
||||
|
||||
|
@ -63,6 +63,7 @@ class Actions
|
||||
# Require admin privileges.
|
||||
@the_call["user-add"] = ->user_add
|
||||
@the_call["user-migrate"] = ->user_migrate
|
||||
@the_call["migration-script"] = ->migration_script
|
||||
@the_call["user-mod"] = ->user_mod
|
||||
|
||||
@the_call["permission-set"] = ->permission_set
|
||||
@ -99,6 +100,26 @@ class Actions
|
||||
puts "error: #{e.message}"
|
||||
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
|
||||
args = Context.args.not_nil!
|
||||
login, email = args[0..1]
|
||||
|
Loading…
Reference in New Issue
Block a user