Class: Morpheus::Cli::Whoami
- Inherits:
-
Object
- Object
- Morpheus::Cli::Whoami
- Includes:
- AccountsHelper, CliCommand, InfrastructureHelper, WhoamiHelper
- Defined in:
- lib/morpheus/cli/whoami.rb
Instance Attribute Summary
Attributes included from CliCommand
Instance Method Summary collapse
- #connect(opts) ⇒ Object
- #handle(args) ⇒ Object
-
#initialize ⇒ Whoami
constructor
no subcommands, just show().
- #show(args) ⇒ Object
Methods included from InfrastructureHelper
#cloud_type_for_id, #cloud_type_for_name, #cloud_type_for_name_or_id, #clouds_interface, #find_cloud_by_id, #find_cloud_by_name, #find_cloud_by_name_or_id, #find_group_by_id, #find_group_by_name, #find_group_by_name_or_id, #get_available_cloud_types, #groups_interface, included
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 WhoamiHelper
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, #usage, #verify_access_token!
Constructor Details
#initialize ⇒ Whoami
no subcommands, just show()
20 21 22 |
# File 'lib/morpheus/cli/whoami.rb', line 20 def initialize() # @appliance_name, @appliance_url = Morpheus::Cli::Remote.active_appliance end |
Instance Method Details
#connect(opts) ⇒ Object
24 25 26 27 28 |
# File 'lib/morpheus/cli/whoami.rb', line 24 def connect(opts) @api_client = establish_remote_appliance_connection(opts) @groups_interface = @api_client.groups @active_group_id = Morpheus::Cli::Groups.active_group end |
#handle(args) ⇒ Object
30 31 32 |
# File 'lib/morpheus/cli/whoami.rb', line 30 def handle(args) show(args) end |
#show(args) ⇒ Object
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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/morpheus/cli/whoami.rb', line 34 def show(args) = {} optparse = OptionParser.new do|opts| opts. = usage opts.on(nil,'--feature-access', "Display Feature Access") do |val| [:include_feature_access] = true end # opts.on(nil,'--group-access', "Display Group Access") do # options[:include_group_access] = true # end # opts.on(nil,'--cloud-access', "Display Cloud Access") do # options[:include_cloud_access] = true # end # opts.on(nil,'--instance-type-access', "Display Instance Type Access") do # options[:include_instance_type_access] = true # end opts.on(nil,'--all-access', "Display All Access Lists") do [:include_feature_access] = true [:include_group_access] = true [:include_cloud_access] = true [:include_instance_type_access] = true end (opts, , [:json, :remote, :dry_run]) # todo: support :remote too end optparse.parse!(args) # todo: check to see if they have credentials instead of just trying to connect (and prompting) connect() begin json_response = load_whoami() group = nil begin group = @active_group_id ? find_group_by_name_or_id(@active_group_id) : nil # via InfrastructureHelper mixin rescue => err if [:debug] print red,"Unable to determine active group: #{err}\n",reset end end if [:json] print JSON.pretty_generate(json_response) print "\n" else user = @current_user if !user puts yellow,"No active session. Please login",reset exit 1 end # todo: impersonate command and show that info here print "\n" ,cyan, bold, "Current User\n","==================", reset, "\n\n" print cyan # if @is_master_account puts "ID: #{user['id']}" puts "Account: #{user['account'] ? user['account']['name'] : nil}" + (@is_master_account ? " (Master Account)" : "") # end puts "First Name: #{user['firstName']}" puts "Last Name: #{user['lastName']}" puts "Username: #{user['username']}" puts "Email: #{user['email']}" puts "Role: #{format_user_role_names(user)}" # puts "Date Created: #{format_local_dt(user['dateCreated'])}" # puts "Last Updated: #{format_local_dt(user['lastUpdated'])}" # print "\n" ,cyan, bold, "User Instance Limits\n","==================", reset, "\n\n" print cyan # puts "Max Storage (bytes): #{user['instanceLimits'] ? user['instanceLimits']['maxStorage'] : 0}" # puts "Max Memory (bytes): #{user['instanceLimits'] ? user['instanceLimits']['maxMemory'] : 0}" # puts "CPU Count: #{user['instanceLimits'] ? user['instanceLimits']['maxCpu'] : 0}" if [:include_feature_access] if @user_permissions print "\n" ,cyan, bold, "Feature Permissions\n","==================", reset, "\n\n" print cyan rows = @user_permissions.collect do |code, access| {code: code, access: get_access_string(access) } end tp rows, [:code, :access] else puts yellow,"No permissions found.",reset end end print "\n" ,cyan, bold, "Remote Appliance\n","==================", reset, "\n\n" print cyan if @appliance_name puts "Name: #{@appliance_name}" end if @appliance_url puts "Url: #{@appliance_url}" end if @appliance_build_verison puts "Build Version: #{@appliance_build_verison}" end print cyan if group print "\n" ,cyan, bold, "Active Group\n","==================", reset, "\n\n" print cyan print "ID: #{group['id']}\n" print "Name: #{group['name']}\n" else print "\n" print "No active group. See `groups use`\n",reset end print reset,"\n" end rescue RestClient::Exception => e print_rest_exception(e, ) if e.response && e.response.code == 401 puts "It looks like you need to login to the remote appliance [#{@appliance_name}] #{@appliance_url}" if Morpheus::Cli::OptionTypes.confirm("Would you like to login now?") return Morpheus::Cli::Login.new.login([]) end end exit 1 end end |