Module: Morpheus::Cli::WhoamiHelper
- Included in:
- Clusters, LibraryOperatingSystemsCommand, NetworkDhcpRelaysCommand, NetworkDhcpServersCommand, NetworkEdgeClustersCommand, NetworkFirewallsCommand, NetworkRoutersCommand, NetworkServerGroups, NetworkStaticRoutesCommand, NetworkTransportZonesCommand, NetworksCommand, PriceSetsCommand, PricesCommand, ProvisioningSettingsCommand, Roles, 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 whoami information
Class Method Summary collapse
Instance Method Summary collapse
- #current_account ⇒ Object
- #current_user ⇒ Object
- #current_user_permissions ⇒ Object
- #is_master_account ⇒ Object
- #load_whoami(refresh = false) ⇒ Object
Class Method Details
.included(klass) ⇒ Object
7 8 9 |
# File 'lib/morpheus/cli/mixins/whoami_helper.rb', line 7 def self.included(klass) klass.send :include, Morpheus::Cli::PrintHelper end |
Instance Method Details
#current_account ⇒ Object
45 46 47 48 49 50 |
# 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 |
#current_user ⇒ Object
59 60 61 62 63 64 |
# File 'lib/morpheus/cli/mixins/whoami_helper.rb', line 59 def current_user if @current_user.nil? load_whoami end @current_user end |
#current_user_permissions ⇒ Object
66 67 68 69 70 71 |
# File 'lib/morpheus/cli/mixins/whoami_helper.rb', line 66 def if @user_permissions.nil? load_whoami end @user_permissions end |
#is_master_account ⇒ Object
52 53 54 55 56 57 |
# 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 |
#load_whoami(refresh = false) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# 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 |