Class: Eso::ConfigurationManager
- Inherits:
-
Object
- Object
- Eso::ConfigurationManager
- 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
-
#nexpose_console ⇒ Object
Returns the value of attribute nexpose_console.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
-
#configuration_by_name(service_name, config_name) ⇒ Eso::Configuration
Return the configuration of a particular service type with a particular name.
- #configuration_type(service_name:) ⇒ Object
-
#delete(configuration_id) ⇒ Object
Delete a configuration.
-
#get_configuration(configuration_id) ⇒ Object
Get a configuration by id.
-
#initialize(nsc) ⇒ Eso::ConfigurationManager
constructor
Constructor for ConfigurationManager.
-
#post_service_configuration(payload) ⇒ Integer
Create a new configuration.
-
#preview_assets(configuration) ⇒ Object
Preview assets for a configuration.
-
#service_configurations(service_name) ⇒ Array
Return all of the configurations of a particular service type.
-
#services ⇒ Array
Return all of the services that are currently supported by this configuration manager.
-
#test_service_configuration(payload) ⇒ String
Test a configuration.
Constructor Details
#initialize(nsc) ⇒ Eso::ConfigurationManager
Constructor for ConfigurationManager.
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_console ⇒ Object
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 |
#url ⇒ Object
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.
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.
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
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
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
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.
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 |
#services ⇒ Array
Return all of the services that are currently supported by this configuration manager.
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
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 |