class Eso::ConfigurationManager

This class represents a configuration manager service, which manages a number of configurations (ie a hostname, port, username, and password) used to connect to services, and the services they connect to (ie, ePO, dxl, palo-alto).

Attributes

nexpose_console[RW]
url[RW]

Public Class Methods

new(nsc) click to toggle source

Constructor for ConfigurationManager.

@param [Nexpose::Connection] nsc A logged-in Nexpose::Connection object with a valid session used to authenticate. @return [Eso::ConfigurationManager] The newly created configurationManager object

# File lib/eso/configuration/configuration_manager.rb, line 15
def initialize(nsc)
  @nexpose_console = nsc
  @url = "https://#{nsc.host}:#{nsc.port}/eso/configuration-manager/api/"
end

Public Instance Methods

configuration_by_name(service_name, config_name) click to toggle source

Return the configuration of a particular service type with a particular name.

@param [String] service_name The name of a service to find configurations of. @param [String] config_name The name of the Configuration. @return [Eso::Configuration] A Configuration object which matches the service name and config name requested.

# File lib/eso/configuration/configuration_manager.rb, line 50
def configuration_by_name(service_name, config_name)
  service_configs_by_type =  service_configurations(service_name)
  config_hash = service_configs_by_type.find { |config| config[:configName] == config_name }
  Eso::Configuration.load(config_hash)
end
configuration_type(service_name:) click to toggle source
# File lib/eso/configuration/configuration_manager.rb, line 56
def configuration_type(service_name:)
  json_data = ::Nexpose::AJAX.get(@nexpose_console,
                                "#{@url}service/configurationType/#{service_name.downcase}",
                                ::Nexpose::AJAX::CONTENT_TYPE::JSON)
  JSON.parse(json_data)
end
delete(configuration_id) click to toggle source

Delete a configuration. Runs a DELETE call against the eso/configuration-manager/api/service/configuration/CONFIGURATION_ID endpoint

@param [String] configuration_id The id of the configuration to delete return [Boolean] Return true if the api reports a successful delete. Raises an error on failure.

# File lib/eso/configuration/configuration_manager.rb, line 105
def delete(configuration_id)
  response_body = ::Nexpose::AJAX.delete(@nexpose_console, "#{@url}service/configuration/#{configuration_id}")
  raise Exception.new("Failed to delete configuration with ID: #{configuration_id}") unless 'success' == response_body
  true
end
get_configuration(configuration_id) click to toggle source

Get a configuration by id. Runs a GET call against the eso/configuration-manager/api/service/configuration/CONFIGURATION_ID endpoint @param [String] configuration_id The id of the configuration to get return [JSON] A json object representing a configuration TODO : Update to use an Eso::Configuration

# File lib/eso/configuration/configuration_manager.rb, line 68
def get_configuration(configuration_id)
  json_data = ::Nexpose::AJAX.get(@nexpose_console, "#{@url}/service/configuration/id/#{configuration_id}", ::Nexpose::AJAX::CONTENT_TYPE::JSON)
  JSON.parse(json_data, :symbolize_names => true)
end
post_service_configuration(payload) click to toggle source

Create a new configuration.

@param [String] payload The JSON representation of a configuration. @return [Integer] The configID (>= 1) of the newly created configuration. Raises error on failure. TODO: Update to use an Eso::Configuration

# File lib/eso/configuration/configuration_manager.rb, line 79
def post_service_configuration(payload)
  # TODO retry if the post fails on timeout
  response_body = ::Nexpose::AJAX.post(@nexpose_console, "#{@url}service/configuration", payload, ::Nexpose::AJAX::CONTENT_TYPE::JSON)
  config_id = Integer(JSON.parse(response_body)['data'])
  raise Exception.new("API returned invalid configID (#{config_id}) while attempting to create configuration.") unless config_id >= 1
  config_id
end
preview_assets(configuration) click to toggle source

Preview assets for a configuration. Calls a POST to the eso/configuration-manager/api/service/configuration/preview endpoint

@param configuration The configuration to preview return [Array] previewed assets TODO: Update to use an Eso::Configuration

# File lib/eso/configuration/configuration_manager.rb, line 117
def preview_assets(configuration)
  response_body = ::Nexpose::AJAX.post(@nexpose_console,
                                     "#{@url}service/configuration/preview",
                                     configuration,
                                     ::Nexpose::AJAX::CONTENT_TYPE::JSON)
  @preview_assets = JSON.parse(response_body)["previewAssets"]
end
service_configurations(service_name) click to toggle source

Return all of the configurations of a particular service type.

@param [String] service_name The name of a service to find configurations of. @return [Array] An array containing all the configurations of the given service type.

# File lib/eso/configuration/configuration_manager.rb, line 37
def service_configurations(service_name)
  json_data = ::Nexpose::AJAX.get(@nexpose_console,
                                "#{@url}service/configuration/#{service_name}/",
                                ::Nexpose::AJAX::CONTENT_TYPE::JSON)
  JSON.parse(json_data, :symbolize_names => true)
end
services() click to toggle source

Return all of the services that are currently supported by this configuration manager.

@return [Array] An array containing all of services in the configuration manager in String object form.

Returns an empty array if no services have been configured.
# File lib/eso/configuration/configuration_manager.rb, line 26
def services
  json_data = ::Nexpose::AJAX.get(@nexpose_console, "#{@url}service/", ::Nexpose::AJAX::CONTENT_TYPE::JSON)
  JSON.parse(json_data)
end
test_service_configuration(payload) click to toggle source

Test a configuration.

@param [String] payload The JSON representation of a configuration. @return [String] The response from the call or an APIError TODO: Update to use an Eso::Configuration

# File lib/eso/configuration/configuration_manager.rb, line 93
def test_service_configuration(payload)
  ::Nexpose::AJAX.post(@nexpose_console,
                     "#{@url}service/configuration/test",
                     payload,
                     ::Nexpose::AJAX::CONTENT_TYPE::JSON)
end