Enable the client to massively purge users.
This commit is contained in:
parent
8c4e64d75b
commit
ed5e449d71
2 changed files with 55 additions and 34 deletions
|
|
@ -35,18 +35,35 @@ opt_email = -> (parser : OptionParser) {
|
||||||
|
|
||||||
|
|
||||||
# Unrecognized parameters are used to create commands with multiple arguments.
|
# Unrecognized parameters are used to create commands with multiple arguments.
|
||||||
# Example: user add login email
|
# Example: user add _login email phone_
|
||||||
# Here, login and email are unrecognized arguments.
|
# Here, login, email and phone are unrecognized arguments.
|
||||||
# Still, the "user add" command expect them.
|
# Still, the "user add" command expect them.
|
||||||
unrecognized_args_to_context_args = -> (parser : OptionParser, n_expected_args : Int32) {
|
unrecognized_args_to_context_args = -> (parser : OptionParser,
|
||||||
|
nexact : Int32?,
|
||||||
|
at_least : Int32?) {
|
||||||
|
|
||||||
# With the right args, these will be interpreted as serialized data.
|
# With the right args, these will be interpreted as serialized data.
|
||||||
parser.unknown_args do |args|
|
parser.unknown_args do |args|
|
||||||
if args.size != n_expected_args
|
|
||||||
Baguette::Log.error "expected number of arguments: #{n_expected_args}, received: #{args.size}"
|
# either we test with the exact expected number of arguments or the least.
|
||||||
Baguette::Log.error "args: #{args}"
|
if exact = nexact
|
||||||
|
if args.size != exact
|
||||||
|
Baguette::Log.error "Wrong number of parameters: expected #{exact}, got #{args.size}"
|
||||||
|
Baguette::Log.error "#{parser}"
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
|
elsif least = at_least
|
||||||
|
if args.size < least
|
||||||
|
Baguette::Log.error "Wrong number of parameters: expected at least #{least}, got #{args.size}"
|
||||||
|
Baguette::Log.error "#{parser}"
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
|
else
|
||||||
|
Baguette::Log.error "Number of parameters not even provided!"
|
||||||
Baguette::Log.error "#{parser}"
|
Baguette::Log.error "#{parser}"
|
||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
|
|
||||||
args.each do |arg|
|
args.each do |arg|
|
||||||
Baguette::Log.debug "Unrecognized argument: #{arg} (adding to Context.args)"
|
Baguette::Log.debug "Unrecognized argument: #{arg} (adding to Context.args)"
|
||||||
if Context.args.nil?
|
if Context.args.nil?
|
||||||
|
|
@ -76,7 +93,7 @@ parser = OptionParser.new do |parser|
|
||||||
opt_profile.call parser
|
opt_profile.call parser
|
||||||
opt_help.call parser
|
opt_help.call parser
|
||||||
# login email
|
# login email
|
||||||
unrecognized_args_to_context_args.call parser, 2
|
unrecognized_args_to_context_args.call parser, 2, nil
|
||||||
end
|
end
|
||||||
|
|
||||||
parser.on "exit", "Kill the service." do
|
parser.on "exit", "Kill the service." do
|
||||||
|
|
@ -85,7 +102,7 @@ parser = OptionParser.new do |parser|
|
||||||
Context.command = "exit"
|
Context.command = "exit"
|
||||||
opt_authd_login.call parser
|
opt_authd_login.call parser
|
||||||
opt_help.call parser
|
opt_help.call parser
|
||||||
unrecognized_args_to_context_args.call parser, 0
|
unrecognized_args_to_context_args.call parser, 0, nil
|
||||||
end
|
end
|
||||||
|
|
||||||
parser.on "migration-script", "Add a batch of users from old code base." do
|
parser.on "migration-script", "Add a batch of users from old code base." do
|
||||||
|
|
@ -96,7 +113,7 @@ parser = OptionParser.new do |parser|
|
||||||
opt_profile.call parser
|
opt_profile.call parser
|
||||||
opt_help.call parser
|
opt_help.call parser
|
||||||
# user-db.txt
|
# user-db.txt
|
||||||
unrecognized_args_to_context_args.call parser, 1
|
unrecognized_args_to_context_args.call parser, 1, nil
|
||||||
end
|
end
|
||||||
|
|
||||||
parser.on "user", "Operations on users." do
|
parser.on "user", "Operations on users." do
|
||||||
|
|
@ -110,7 +127,7 @@ parser = OptionParser.new do |parser|
|
||||||
opt_profile.call parser
|
opt_profile.call parser
|
||||||
opt_help.call parser
|
opt_help.call parser
|
||||||
# login email
|
# login email
|
||||||
unrecognized_args_to_context_args.call parser, 2
|
unrecognized_args_to_context_args.call parser, 2, nil
|
||||||
end
|
end
|
||||||
|
|
||||||
parser.on "migrate", "Add a user from old code base." do
|
parser.on "migrate", "Add a user from old code base." do
|
||||||
|
|
@ -121,7 +138,7 @@ parser = OptionParser.new do |parser|
|
||||||
opt_profile.call parser
|
opt_profile.call parser
|
||||||
opt_help.call parser
|
opt_help.call parser
|
||||||
# login password-hash-brkn
|
# login password-hash-brkn
|
||||||
unrecognized_args_to_context_args.call parser, 2
|
unrecognized_args_to_context_args.call parser, 2, nil
|
||||||
end
|
end
|
||||||
|
|
||||||
parser.on "mod", "Modify a user account." do
|
parser.on "mod", "Modify a user account." do
|
||||||
|
|
@ -133,7 +150,7 @@ parser = OptionParser.new do |parser|
|
||||||
opt_profile.call parser
|
opt_profile.call parser
|
||||||
opt_help.call parser
|
opt_help.call parser
|
||||||
# userid
|
# userid
|
||||||
unrecognized_args_to_context_args.call parser, 1
|
unrecognized_args_to_context_args.call parser, 1, nil
|
||||||
end
|
end
|
||||||
|
|
||||||
parser.on "change-password", "Change the password of a user (requires admin)." do
|
parser.on "change-password", "Change the password of a user (requires admin)." do
|
||||||
|
|
@ -145,18 +162,18 @@ parser = OptionParser.new do |parser|
|
||||||
opt_profile.call parser
|
opt_profile.call parser
|
||||||
opt_help.call parser
|
opt_help.call parser
|
||||||
# userid
|
# userid
|
||||||
unrecognized_args_to_context_args.call parser, 1
|
unrecognized_args_to_context_args.call parser, 1, nil
|
||||||
end
|
end
|
||||||
|
|
||||||
parser.on "delete", "Remove user." do
|
parser.on "delete", "Remove user." do
|
||||||
parser.banner = "Usage: user delete userid [opt]"
|
parser.banner = "Usage: user delete userid [userid ...]"
|
||||||
Baguette::Log.info "Remove user."
|
Baguette::Log.info "Remove user."
|
||||||
Context.command = "user-delete"
|
Context.command = "user-delete"
|
||||||
# You can either be the owner of the account, or an admin.
|
# You can either be the owner of the account, or an admin.
|
||||||
opt_authd_login.call parser
|
opt_authd_login.call parser
|
||||||
opt_help.call parser
|
opt_help.call parser
|
||||||
# userid
|
# userid
|
||||||
unrecognized_args_to_context_args.call parser, 1
|
unrecognized_args_to_context_args.call parser, nil, 1
|
||||||
end
|
end
|
||||||
|
|
||||||
parser.on "validate", "Validate user." do
|
parser.on "validate", "Validate user." do
|
||||||
|
|
@ -166,7 +183,7 @@ parser = OptionParser.new do |parser|
|
||||||
# No need to be authenticated.
|
# No need to be authenticated.
|
||||||
opt_help.call parser
|
opt_help.call parser
|
||||||
# login activation-key
|
# login activation-key
|
||||||
unrecognized_args_to_context_args.call parser, 2
|
unrecognized_args_to_context_args.call parser, 2, nil
|
||||||
end
|
end
|
||||||
|
|
||||||
parser.on "get", "Get user info." do
|
parser.on "get", "Get user info." do
|
||||||
|
|
@ -176,17 +193,17 @@ parser = OptionParser.new do |parser|
|
||||||
opt_authd_login.call parser
|
opt_authd_login.call parser
|
||||||
opt_help.call parser
|
opt_help.call parser
|
||||||
# login
|
# login
|
||||||
unrecognized_args_to_context_args.call parser, 1
|
unrecognized_args_to_context_args.call parser, nil, 1
|
||||||
end
|
end
|
||||||
|
|
||||||
parser.on "search", "Search user." do
|
parser.on "search", "Search user." do
|
||||||
parser.banner = "Usage: user search login [opt]"
|
parser.banner = "Usage: user search login [login...]"
|
||||||
Baguette::Log.info "Search user."
|
Baguette::Log.info "Search user."
|
||||||
Context.command = "user-search"
|
Context.command = "user-search"
|
||||||
opt_authd_login.call parser
|
opt_authd_login.call parser
|
||||||
opt_help.call parser
|
opt_help.call parser
|
||||||
# login
|
# login
|
||||||
unrecognized_args_to_context_args.call parser, 1
|
unrecognized_args_to_context_args.call parser, nil, 1
|
||||||
end
|
end
|
||||||
|
|
||||||
parser.on "recover", "Recover user password." do
|
parser.on "recover", "Recover user password." do
|
||||||
|
|
@ -196,7 +213,7 @@ parser = OptionParser.new do |parser|
|
||||||
# No need to be authenticated.
|
# No need to be authenticated.
|
||||||
opt_help.call parser
|
opt_help.call parser
|
||||||
# login
|
# login
|
||||||
unrecognized_args_to_context_args.call parser, 1
|
unrecognized_args_to_context_args.call parser, nil, 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -208,7 +225,7 @@ parser = OptionParser.new do |parser|
|
||||||
opt_profile.call parser
|
opt_profile.call parser
|
||||||
opt_help.call parser
|
opt_help.call parser
|
||||||
# login email
|
# login email
|
||||||
unrecognized_args_to_context_args.call parser, 2
|
unrecognized_args_to_context_args.call parser, 2, nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -226,7 +243,7 @@ END
|
||||||
opt_authd_login.call parser
|
opt_authd_login.call parser
|
||||||
opt_help.call parser
|
opt_help.call parser
|
||||||
# userid application resource permission
|
# userid application resource permission
|
||||||
unrecognized_args_to_context_args.call parser, 4
|
unrecognized_args_to_context_args.call parser, 4, nil
|
||||||
end
|
end
|
||||||
|
|
||||||
parser.on "check", "Check permissions." do
|
parser.on "check", "Check permissions." do
|
||||||
|
|
@ -241,7 +258,7 @@ END
|
||||||
opt_authd_login.call parser
|
opt_authd_login.call parser
|
||||||
opt_help.call parser
|
opt_help.call parser
|
||||||
# userid application resource
|
# userid application resource
|
||||||
unrecognized_args_to_context_args.call parser, 3
|
unrecognized_args_to_context_args.call parser, 3, nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -243,11 +243,12 @@ class Actions
|
||||||
|
|
||||||
def user_deletion
|
def user_deletion
|
||||||
args = Context.args.not_nil!
|
args = Context.args.not_nil!
|
||||||
userid = args[0].to_u32
|
args.each do |u|
|
||||||
|
Baguette::Log.info "Removing user #{u}…"
|
||||||
res = authd.delete userid
|
userid = u.to_u32
|
||||||
|
res = authd.delete userid
|
||||||
puts res
|
puts res
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def user_validation
|
def user_validation
|
||||||
|
|
@ -257,18 +258,21 @@ class Actions
|
||||||
end
|
end
|
||||||
def user_search
|
def user_search
|
||||||
args = Context.args.not_nil!
|
args = Context.args.not_nil!
|
||||||
login = args[0]
|
args.each do |login|
|
||||||
pp! authd.search_user login
|
pp! authd.search_user login
|
||||||
|
end
|
||||||
end
|
end
|
||||||
def user_get
|
def user_get
|
||||||
args = Context.args.not_nil!
|
args = Context.args.not_nil!
|
||||||
login = args[0]
|
args.each do |login|
|
||||||
pp! authd.get_user? login
|
pp! authd.get_user? login
|
||||||
|
end
|
||||||
end
|
end
|
||||||
def user_recovery
|
def user_recovery
|
||||||
args = Context.args.not_nil!
|
args = Context.args.not_nil!
|
||||||
login = args[0]
|
args.each do |login|
|
||||||
pp! authd.ask_password_recovery login
|
pp! authd.ask_password_recovery login
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def permission_check
|
def permission_check
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue