User password can be given on cli for automatic user creation.

ipc07
Philippe PITTOLI 2020-04-17 02:45:30 +02:00
parent 810c224fae
commit ad7609a0f1
1 changed files with 15 additions and 8 deletions

View File

@ -8,6 +8,7 @@ profile_file : String? = nil
register = false
email = nil
phone = nil
password : String? = nil
OptionParser.parse do |parser|
parser.unknown_args do |args|
@ -24,6 +25,10 @@ OptionParser.parse do |parser|
profile_file = file
end
parser.on "-X user-password", "--user-password pass", "Read the new user password." do |pass|
password = pass
end
parser.on "-K file", "--key-file file", "Read the authd shared key from a file." do |file|
key_file = file
end
@ -55,13 +60,15 @@ profile = profile_file.try do |file|
end
end
STDOUT << "password: "
STDOUT << `stty -echo`
STDOUT.flush
password = STDIN.gets.try &.chomp
if password.nil?
STDOUT << "password: "
STDOUT << `stty -echo`
STDOUT.flush
password = STDIN.gets.try &.chomp
STDOUT << '\n'
STDOUT << `stty echo`
STDOUT << '\n'
STDOUT << `stty echo`
end
exit 1 unless password
@ -72,13 +79,13 @@ phone = nil if phone == ""
begin
if register
pp! authd.register login, password, email, phone, profile: profile
pp! authd.register login, password.not_nil!, email, phone, profile: profile
else
key_file.try do |file| # FIXME: fail if missing?
authd.key = File.read(file).chomp
end
pp! authd.add_user login, password, email, phone, profile: profile
pp! authd.add_user login, password.not_nil!, email, phone, profile: profile
end
rescue e : AuthD::Exception
puts "error: #{e.message}"