Sha256: 02e4229c71f6d7a1663bf10982f019a70f923c4a6a8012cbf14c22383dad10e0

Contents?: true

Size: 1.62 KB

Versions: 1

Compression:

Stored size: 1.62 KB

Contents

require 'mixlib/cli'
require 'spanx/logger'

class Spanx::CLI::Flush < Spanx::CLI

  banner 'Usage: spanx flush [ -a | -i IPADDRESS ] [options]'
  description 'Remove a specific IP block, or all blocked IPs'

  option :ip,
         :short => '-i IPADDRESS',
         :long => '--ip IPADDRESS',
         :description => 'Unblock specific IP',
         :required => false

  option :all,
         :short => '-a',
         :long => '--all',
         :description => 'Unblock all IPs',
         :required => false

  option :config_file,
         :short => '-c CONFIG',
         :long => '--config CONFIG',
         :description => 'Path to config file (YML)',
         :required => true

  option :debug,
         :short => '-g',
         :long => '--debug',
         :description => 'Log to STDOUT status of execution and some time metrics',
         :boolean => true,
         :required => false,
         :default => false

  option :help,
         :short => "-h",
         :long => "--help",
         :description => "Show this message",
         :on => :tail,
         :boolean => true,
         :show_options => true,
         :exit => 0


  def run(argv = ARGV)
    generate_config(argv)
    out = ''
    keys = if config[:ip] =~ /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/
      out << "unblocking ip #{config[:ip]}: "
      Spanx::IPChecker.new(config[:ip]).unblock
    elsif config[:all]
      out << 'unblocking all IPs: ' if config[:debug]
      Spanx::IPChecker.unblock_all
    else
      error_exit_with_msg 'Either -i or -a flag is required now'
    end
    out << "deleted #{keys} IPs that matched"
    puts out if config[:debug]
    out
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
spanx-0.3.0 lib/spanx/cli/flush.rb