Class: Eso::ConfigurationManager

Inherits:
Object
  • Object
show all
Defined in:
lib/eso/configuration/configuration_manager.rb

Overview

port, username, and password) used to connect to services, and the services they connect to (ie, ePO, dxl, palo-alto).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nsc) ⇒ Eso::ConfigurationManager

Constructor for ConfigurationManager.

Parameters:

  • nsc (Nexpose::Connection)

    A logged-in Nexpose::Connection object with a valid session used to authenticate.



15
16
17
18
# 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

Instance Attribute Details

#nexpose_consoleObject

Returns the value of attribute nexpose_console.



7
8
9
# File 'lib/eso/configuration/configuration_manager.rb', line 7

def nexpose_console
  @nexpose_console
end

#urlObject

Returns the value of attribute url.



7
8
9
# File 'lib/eso/configuration/configuration_manager.rb', line 7

def url
  @url
end

Instance Method Details

#configuration_by_name(service_name, config_name) ⇒ Eso::Configuration

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

Parameters:

  • service_name (String)

    The name of a service to find configurations of.

  • config_name (String)

    The name of the Configuration.

Returns:

  • (Eso::Configuration)

    A Configuration object which matches the service name and config name requested.



50
51
52
53
54
# 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:) ⇒ Object



56
57
58
59
60
61
# 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) ⇒ Object

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

return [Boolean] Return true if the api reports a successful delete. Raises an error on failure.

Parameters:

  • configuration_id (String)

    The id of the configuration to delete

Raises:

  • (Exception)


105
106
107
108
109
# 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) ⇒ Object

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

Parameters:

  • configuration_id (String)

    The id of the configuration to get



68
69
70
71
# 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) ⇒ Integer

Create a new configuration.

TODO: Update to use an Eso::Configuration

Parameters:

  • payload (String)

    The JSON representation of a configuration.

Returns:

  • (Integer)

    The configID (>= 1) of the newly created configuration. Raises error on failure.

Raises:

  • (Exception)


79
80
81
82
83
84
85
# 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) ⇒ Object

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

return [Array] previewed assets TODO: Update to use an Eso::Configuration

Parameters:

  • configuration

    The configuration to preview



117
118
119
120
121
122
123
# 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) ⇒ Array

Return all of the configurations of a particular service type.

Parameters:

  • service_name (String)

    The name of a service to find configurations of.

Returns:

  • (Array)

    An array containing all the configurations of the given service type.



37
38
39
40
41
42
# 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

#servicesArray

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

Returns:

  • (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.



26
27
28
29
# 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) ⇒ String

Test a configuration.

TODO: Update to use an Eso::Configuration

Parameters:

  • payload (String)

    The JSON representation of a configuration.

Returns:

  • (String)

    The response from the call or an APIError



93
94
95
96
97
98
# 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