Class: Morpheus::Cli::RecentActivityCommand

Inherits:
Object
  • Object
show all
Includes:
AccountsHelper, CliCommand
Defined in:
lib/morpheus/cli/recent_activity_command.rb

Instance Attribute Summary

Attributes included from CliCommand

#no_prompt

Instance Method Summary collapse

Methods included from AccountsHelper

#accounts_interface, #find_account_by_id, #find_account_by_name, #find_account_by_name_or_id, #find_account_from_options, #find_role_by_id, #find_role_by_name, #find_role_by_name_or_id, #find_user_by_id, #find_user_by_username, #find_user_by_username_or_id, #format_role_type, #format_user_role_names, #get_access_string, included, #print_accounts_table, #print_roles_table, #print_users_table, #roles_interface, #users_interface

Methods included from CliCommand

#build_common_options, #build_option_type_options, #command_name, #default_subcommand, #establish_remote_appliance_connection, #handle_subcommand, included, #interactive?, #noninteractive, #print_usage, #subcommand_aliases, #subcommand_usage, #subcommands, #verify_access_token!

Constructor Details

#initializeRecentActivityCommand

Returns a new instance of RecentActivityCommand.



13
14
15
# File 'lib/morpheus/cli/recent_activity_command.rb', line 13

def initialize()
  # @appliance_name, @appliance_url = Morpheus::Cli::Remote.active_appliance
end

Instance Method Details

#connect(opts) ⇒ Object



17
18
19
20
21
# File 'lib/morpheus/cli/recent_activity_command.rb', line 17

def connect(opts)
  @api_client = establish_remote_appliance_connection(opts)
  @dashboard_interface = @api_client.dashboard
  @accounts_interface = @api_client.accounts
end

#handle(args) ⇒ Object



27
28
29
# File 'lib/morpheus/cli/recent_activity_command.rb', line 27

def handle(args)
  list(args)
end

#list(args) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/morpheus/cli/recent_activity_command.rb', line 30

def list(args)
  options = {}
  optparse = OptionParser.new do|opts|
    opts.banner = usage
    opts.on('--start TIMESTAMP','--start TIMESTAMP', "Start timestamp. Default is 30 days ago.") do |val|
      options[:start] = parse_time(val).iso8601
    end
    opts.on('--end TIMESTAMP','--end TIMESTAMP', "End timestamp. Default is now.") do |val|
      options[:end] = parse_time(val).iso8601
    end
    build_common_options(opts, options, [:account, :list, :json, :dry_run])
  end
  optparse.parse!(args)
  connect(options)
  begin
     = (options)
     =  ? ['id'] : nil
    params = {}
    [:phrase, :offset, :max, :sort, :direction, :start, :end].each do |k|
      params[k] = options[k] unless options[k].nil?
    end
    if options[:dry_run]
      print_dry_run @dashboard_interface.dry.recent_activity(, params)
      return
    end
    json_response = @dashboard_interface.recent_activity(, params)
    if options[:json]
      print JSON.pretty_generate(json_response)
      print "\n"
    else

      # todo: impersonate command and show that info here

      print "\n" ,cyan, bold, "Dashboard\n","==================", reset, "\n\n"
      print cyan
      print "\n"
      puts "Coming soon.... see --json"
      print "\n"

      print reset,"\n"

    end
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#usageObject



23
24
25
# File 'lib/morpheus/cli/recent_activity_command.rb', line 23

def usage
  "Usage: morpheus #{command_name}"
end