From 4c1b4c43c263a71e3a56c9f26282f12e8817c791 Mon Sep 17 00:00:00 2001 From: Karchnu Date: Tue, 13 Oct 2020 18:00:48 +0200 Subject: [PATCH] authc --- shard.yml | 18 ----- utils/authc.cr | 1 - utils/parse-me.cr | 165 ---------------------------------------------- 3 files changed, 184 deletions(-) delete mode 100644 utils/parse-me.cr diff --git a/shard.yml b/shard.yml index 5350cc9..2e10eef 100644 --- a/shard.yml +++ b/shard.yml @@ -14,24 +14,6 @@ targets: authc: main: utils/authc.cr -# TO REMOVE - auth-user-perms: - main: utils/authd-user-perms.cr - auth-user-add: - main: utils/authd-user-add.cr - auth-user-allow: - main: utils/authd-user-allow.cr - auth-user-ask-for-new-password: - main: utils/authd-user-ask-for-new-password.cr - auth-user-get: - main: utils/authd-user-get.cr - auth-user-mod: - main: utils/authd-user-mod.cr - auth-user-validate: - main: utils/authd-user-validate.cr - auth-user-search: - main: utils/authd-user-search.cr - crystal: 0.35.1 dependencies: diff --git a/utils/authc.cr b/utils/authc.cr index cb56d4a..5edd5a0 100644 --- a/utils/authc.cr +++ b/utils/authc.cr @@ -31,7 +31,6 @@ class Context class_property phone : String? class_property email : String? - # TODO: inner arguments. # Will be parsed later, with a specific parser. class_property args : Array(String)? = nil end diff --git a/utils/parse-me.cr b/utils/parse-me.cr deleted file mode 100644 index 0e9dad3..0000000 --- a/utils/parse-me.cr +++ /dev/null @@ -1,165 +0,0 @@ -require "phreak" - -opt_help = -> (root : Phreak::RootParser) { - root.bind(short_flag: 'h', long_flag: "help", description: "Get some help.") do |sub| - puts root - exit 0 - end -} - -opt_help_sub = -> (root : Phreak::Subparser) { - root.bind(short_flag: 'h', long_flag: "help", description: "Get some help.") do |sub| - puts root - exit 0 - end -} - -opt_verbosity = -> (root : Phreak::RootParser) { - root.bind(short_flag: 'v', long_flag: "verbosity", description: "Verbosity.") do |sub| - next_token = root.next_token - Baguette::Context.verbosity = next_token.to_i - Baguette::Log.info "Verbosity: #{Baguette::Context.verbosity}." - end -} - -class Blah - class_property next_token = "bla" -end - -# frequently used functions -opt_authd_login = -> (root : Phreak::Subparser) { - root.bind(short_flag: 'l', long_flag: "login", description: "Authd user login.") do |sub| - sub.grab do |sub, name| - Blah.next_token = name - end - Context.authd_login = Blah.next_token - Baguette::Log.info "User login for authd: #{Context.authd_login}." - end - root.bind(short_flag: 'p', long_flag: "password", description: "Authd user password.") do |sub| - sub.grab do |sub, name| - Blah.next_token = name - end - Context.authd_pass = Blah.next_token - Baguette::Log.info "User password for authd: #{Context.authd_pass}." - end -} - -opt_authd_admin = -> (root : Phreak::Subparser) { - root.bind(short_flag: 'k', long_flag: "key-file", description: "Read the authd shared key from a file.") do |sub| - puts "Reading the next token !!" - sub.grab do |sub, name| - puts "here reading the next token: #{name}" - Blah.next_token = name - key_file = Blah.next_token - Context.shared_key = File.read(key_file).chomp - Baguette::Log.info "Key for admin operations: #{Context.shared_key}." - end - end -} - -opt_simulation = -> (root : Phreak::RootParser) { - root.bind(short_flag: 's', long_flag: "simulation", description: "Don't do anything.") do |sub| - Baguette::Log.info "This is a simulation." - Context.simulation = true - end -} - -opt_args = -> (root : Phreak::RootParser) { - # With the right args, these will be interpreted as serialized data. - # See "deal-add" for example. - root.unrecognized_args do |arg| - Baguette::Log.debug "Unrecognized argument: #{arg} (adding to Context.args)" - if Context.args.nil? - Context.args = Array(String).new - end - Context.args.not_nil! << arg - end -} - -parser_user_add = -> (root : Phreak::Subparser) { - root.missing_args do |apex| - Baguette::Log.info "Missing an argument after #{apex}" - end - - # TODO? - root.unrecognized_args do |arg| - Baguette::Log.warning "Unrecognized argument: #{arg}" - Baguette::Log.warning "#{root.banner}" - end - - # opt_args.call root - root.banner = "Usage: user-add user-id email phone [opt]" - opt_help_sub.call root -} - -class Phreak::Subparser - property parent : Phreak::Subparser? -end - -# Parsing arguments is reading and understanding the intent, not doing anything. -Phreak.parse! do |root| - - # Admin section. - root.bind(word: "user-add", description: "user-add") do |sub| - Baguette::Log.info "user-add" - Context.command = "user-add" - parser_user_add.call sub - opt_profile.call sub - opt_authd_admin.call sub - end - - root.bind(word: "user-mod", description: "user-mod") do |sub| - Baguette::Log.info "user-mod" - Context.command = "user-mod" - opt_profile.call sub - opt_authd_admin.call sub - end - - root.bind(word: "delete", description: "Remove user.") do |sub| - Baguette::Log.info "Remove user." - Context.command = "delete" - opt_authd_admin.call sub - end - - root.bind(word: "set-permissions", description: "Set permissions.") do |sub| - Baguette::Log.info "Set permissions." - Context.command = "set-permissions" - opt_authd_admin.call sub - end - - root.bind(word: "check-permissions", description: "Check permissions.") do |sub| - Baguette::Log.info "Check permissions." - Context.command = "check-permissions" - opt_authd_admin.call sub - end - - # Do not require to be admin. - root.bind(word: "registration", description: "Register a user.") do |sub| - Baguette::Log.info "Register a user." - Context.command = "registration" - opt_profile.call sub - opt_authd_login.call sub - end - - - root.default do - Baguette::Log.info "No arguments provided" - end - - root.missing_args do |apex| - Baguette::Log.info "Missing an argument after #{apex}" - end - - opt_args.call root - - root.banner = "Usage: #{PROGRAM_NAME} [opts] command [other options]" - opt_help.call root - opt_verbosity.call root - opt_simulation.call root - - root.bind(word: "help", description: "Get some help.") do |sub| - Baguette::Log.info "Help" - Baguette::Log.info root - exit 0 - end -end