Class: Morpheus::Cli::Whoami
- Inherits:
-
Object
- Object
- Morpheus::Cli::Whoami
- Includes:
- AccountsHelper, CliCommand, WhoamiHelper
- Defined in:
- lib/morpheus/cli/whoami.rb
Instance Method Summary collapse
- #connect(opts) ⇒ Object
- #handle(args) ⇒ Object
-
#initialize ⇒ Whoami
constructor
A new instance of Whoami.
- #show(args) ⇒ Object
- #usage ⇒ Object
Methods included from AccountsHelper
#find_account_by_id, #find_account_by_name, #find_account_from_options, #find_role_by_id, #find_role_by_name, #find_user_by_id, #find_user_by_username, #format_role_type, #format_user_role_names, #get_access_string, included, #print_accounts_table, #print_roles_table, #print_users_table
Methods included from WhoamiHelper
Methods included from CliCommand
#build_common_options, included
Constructor Details
#initialize ⇒ Whoami
Returns a new instance of Whoami.
15 16 17 18 |
# File 'lib/morpheus/cli/whoami.rb', line 15 def initialize() @appliance_name, @appliance_url = Morpheus::Cli::Remote.active_appliance @active_groups = ::Morpheus::Cli::Groups.load_group_file end |
Instance Method Details
#connect(opts) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/morpheus/cli/whoami.rb', line 20 def connect(opts) @access_token = Morpheus::Cli::Credentials.new(@appliance_name,@appliance_url).load_saved_credentials() # always try this.. it will 401 # if @access_token.empty? # print_red_alert "Invalid Credentials. Unable to acquire access token. Please verify your credentials and try again." # exit 1 # end @api_client = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url) end |
#handle(args) ⇒ Object
36 37 38 |
# File 'lib/morpheus/cli/whoami.rb', line 36 def handle(args) show(args) end |
#show(args) ⇒ Object
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 |
# File 'lib/morpheus/cli/whoami.rb', line 40 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]) # todo: support :remote too end optparse.parse(args) connect() begin json_response = load_whoami() 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 print reset,"\n" end rescue RestClient::Exception => e print_rest_exception(e, ) exit 1 end end |
#usage ⇒ Object
32 33 34 |
# File 'lib/morpheus/cli/whoami.rb', line 32 def usage "Usage: morpheus whoami" end |