Module: Morpheus::Cli::WhoamiHelper
- Included in:
- Clusters, NetworkRoutersCommand, NetworksCommand, PriceSetsCommand, PricesCommand, ProvisioningSettingsCommand, Users, Whoami
- Defined in:
- lib/morpheus/cli/mixins/whoami_helper.rb
Overview
Mixin for Morpheus::Cli command classes Provides common methods for fetching and printing accounts, roles, and users. The including class must establish @accounts_interface, @roles_interface, @users_interface
Class Method Summary collapse
Instance Method Summary collapse
- #current_account ⇒ Object
- #current_user ⇒ Object
- #current_user_permissions ⇒ Object
- #is_master_account ⇒ Object
- #load_whoami ⇒ Object
Class Method Details
.included(klass) ⇒ Object
8 9 10 |
# File 'lib/morpheus/cli/mixins/whoami_helper.rb', line 8 def self.included(klass) klass.send :include, Morpheus::Cli::PrintHelper end |
Instance Method Details
#current_account ⇒ Object
32 33 34 35 36 37 |
# File 'lib/morpheus/cli/mixins/whoami_helper.rb', line 32 def current_account if @current_user.nil? load_whoami end @current_user ? @current_user['account'] : nil end |
#current_user ⇒ Object
46 47 48 49 50 51 |
# File 'lib/morpheus/cli/mixins/whoami_helper.rb', line 46 def current_user if @current_user.nil? load_whoami end @current_user end |
#current_user_permissions ⇒ Object
53 54 55 56 57 58 |
# File 'lib/morpheus/cli/mixins/whoami_helper.rb', line 53 def if @user_permissions.nil? load_whoami end @user_permissions end |
#is_master_account ⇒ Object
39 40 41 42 43 44 |
# File 'lib/morpheus/cli/mixins/whoami_helper.rb', line 39 def is_master_account if @current_user.nil? load_whoami end @is_master_account end |
#load_whoami ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/morpheus/cli/mixins/whoami_helper.rb', line 12 def load_whoami() whoami_interface = @whoami_interface || @api_client.whoami whoami_response = whoami_interface.get() # whoami_response = @whoami_interface.get() @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 |