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
Public Class Methods
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
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
# 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 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 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
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 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
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
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 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