module Morpheus::Cli::WhoamiHelper
Mixin for Morpheus::Cli
command classes Provides common methods for fetching and printing whoami information
Public Class Methods
Source
# File lib/morpheus/cli/mixins/whoami_helper.rb, line 7 def self.included(klass) klass.send :include, Morpheus::Cli::PrintHelper end
Public Instance Methods
Source
# File lib/morpheus/cli/mixins/whoami_helper.rb, line 45 def current_account if @current_user.nil? load_whoami end @current_user ? @current_user['account'] : nil end
Source
# File lib/morpheus/cli/mixins/whoami_helper.rb, line 59 def current_user if @current_user.nil? load_whoami end @current_user end
Source
# File lib/morpheus/cli/mixins/whoami_helper.rb, line 66 def current_user_permissions if @user_permissions.nil? load_whoami end @user_permissions end
Source
# File lib/morpheus/cli/mixins/whoami_helper.rb, line 52 def is_master_account if @current_user.nil? load_whoami end @is_master_account end
Source
# File lib/morpheus/cli/mixins/whoami_helper.rb, line 11 def load_whoami(refresh=false) appliance = @remote_appliance # from establish_connection() if appliance.nil? print_red_alert "No current appliance. See `remote use`." exit 1 end # fetch from cache first whoami_response = nil cached_response = ::Morpheus::Cli::Whoami.load_whoami(appliance[:name], appliance[:username], refresh) if cached_response whoami_response = cached_response else whoami_interface = @whoami_interface || @api_client.whoami whoami_response = whoami_interface.get() # save the result to the cache ::Morpheus::Cli::Whoami.save_whoami(appliance[:name], appliance[:username], whoami_response) end @current_user = whoami_response["user"] if @current_user.empty? print_red_alert "Unauthenticated. Please login." exit 1 end @is_master_account = whoami_response["isMasterAccount"] @user_permissions = whoami_response["permissions"] if whoami_response["appliance"] @appliance_build_verison = whoami_response["appliance"]["buildVersion"] else @appliance_build_verison = nil end return whoami_response end