Sha256: 7c49a194793fcd2e1123d4c57a8809a324c12664e22362221a8d34879d38f167

Contents?: true

Size: 1.42 KB

Versions: 2

Compression:

Stored size: 1.42 KB

Contents

module HammerCLIForeman

  class Auth < HammerCLI::AbstractCommand

    class LoginCommand < HammerCLI::AbstractCommand
      command_name "login"
      desc _("Set credentials")

      def execute
        HammerCLIForeman.credentials.clear
        HammerCLI::Connection.drop_all
        HammerCLIForeman.credentials.username
        HammerCLIForeman.credentials.password
        HammerCLI::EX_OK
      end
    end

    class LogoutCommand < HammerCLI::AbstractCommand
      command_name "logout"
      desc _("Wipe your credentials")

      def execute
        #NOTE: we will change that to drop(:foreman) once dynamic bindings are implemented
        HammerCLIForeman.credentials.clear
        HammerCLI::Connection.drop_all
        print_message(_("Credentials deleted."))
        HammerCLI::EX_OK
      end
    end

    class InfoCommand < HammerCLI::AbstractCommand
      command_name "status"
      desc _("Information about current connections")

      def execute
        unless HammerCLIForeman.credentials.empty?
          print_message(_("You are logged in as '%s'") % HammerCLIForeman.credentials.username)
        else
          print_message(_("You are currently not logged in to any service.\nUse the service to set credentials."))
        end
        HammerCLI::EX_OK
      end
    end

    autoload_subcommands
  end

  HammerCLI::ShellMainCommand.subcommand 'auth', _("Foreman connection login/logout."), HammerCLIForeman::Auth
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hammer_cli_foreman-0.1.1 lib/hammer_cli_foreman/auth.rb
hammer_cli_foreman-0.1.0 lib/hammer_cli_foreman/auth.rb