From ad7609a0f1070b39a6ceec7feb9d6ad183f69d35 Mon Sep 17 00:00:00 2001
From: Philippe PITTOLI
Date: Fri, 17 Apr 2020 02:45:30 +0200
Subject: [PATCH] User password can be given on cli for automatic user
creation.
---
utils/authd-user-add.cr | 23 +++++++++++++++--------
1 file changed, 15 insertions(+), 8 deletions(-)
diff --git a/utils/authd-user-add.cr b/utils/authd-user-add.cr
index 8f5405d..4028f37 100644
--- a/utils/authd-user-add.cr
+++ b/utils/authd-user-add.cr
@@ -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}"