Skip to content

Commit

Permalink
Merge pull request #1652 from enoodle/container_provider_settings
Browse files Browse the repository at this point in the history
Add the ability to edit options settings for providers
  • Loading branch information
Dan Clarizio authored Oct 19, 2017
2 parents b926d5f + 0340e80 commit ab3f23e
Show file tree
Hide file tree
Showing 15 changed files with 444 additions and 23 deletions.
16 changes: 16 additions & 0 deletions app/assets/javascripts/components/provider-option-field-input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
ManageIQ.angular.app.component('providerOptionFieldInput', {
bindings: {
option: '<',
sectionName: '@',
},

controller: function() {
var ctrl = this;

ctrl.$onInit = function() {
ctrl.elemID = "provider_options_" + ctrl.sectionName + "_" + ctrl.option.name;
};
},

templateUrl: '/static/provider_option_field_input.html.haml',
});
11 changes: 11 additions & 0 deletions app/assets/javascripts/components/provier-option-section.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ManageIQ.angular.app.component('providerOptionSection', {
bindings: {
settings: '<',
label: '@',
helpText: '@',
sectionName: '@',
},

templateUrl: '/static/provider_option_section.html.haml',
});

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ManageIQ.angular.app.controller('emsCommonFormController', ['$http', '$scope', '$attrs', 'emsCommonFormId', 'miqService', '$timeout', function($http, $scope, $attrs, emsCommonFormId, miqService, $timeout) {
ManageIQ.angular.app.controller('emsCommonFormController', ['$http', '$scope', '$attrs', 'emsCommonFormId', 'miqService', '$timeout', 'API', function($http, $scope, $attrs, emsCommonFormId, miqService, $timeout, API) {
var init = function() {
$scope.emsCommonModel = {
name: '',
Expand All @@ -10,6 +10,7 @@ ManageIQ.angular.app.controller('emsCommonFormController', ['$http', '$scope', '
hostname: '',
default_hostname: '',
amqp_hostname: '',
provider_options: {},
metrics_hostname: '',
metrics_selection: '',
metrics_api_port: '',
Expand Down Expand Up @@ -59,6 +60,12 @@ ManageIQ.angular.app.controller('emsCommonFormController', ['$http', '$scope', '
prometheus_alerts_security_protocol: '',
alerts_selection: '',
};

$scope.emsOptionsModel = {
provider_options: {},
provider_options_original_values: {},
};

$scope.formId = emsCommonFormId;
$scope.afterGet = false;
$scope.modelCopy = angular.copy( $scope.emsCommonModel );
Expand Down Expand Up @@ -177,6 +184,9 @@ ManageIQ.angular.app.controller('emsCommonFormController', ['$http', '$scope', '
$scope.populatePostValidationModel();

miqService.sparkleOff();

$scope.emsOptionsModel.provider_options_original_values = data.provider_options;
$scope.updateProviderOptionsDescription();
}

function getNewEmsFormDataComplete(response) {
Expand Down Expand Up @@ -272,7 +282,8 @@ ManageIQ.angular.app.controller('emsCommonFormController', ['$http', '$scope', '
$scope.emsCommonModel.metrics_api_port) ||
($scope.currentTab === "alerts" &&
$scope.emsCommonModel.prometheus_alerts_hostname !== '' &&
$scope.emsCommonModel.prometheus_alerts_api_port !== ''))) {
$scope.emsCommonModel.prometheus_alerts_api_port !== '') ||
($scope.currentTab === "proxy_settings") || ($scope.currentTab === "advanced_settings"))) {
return true;
} else if($scope.emsCommonModel.emstype == "gce" && $scope.emsCommonModel.project != '' &&
($scope.currentTab == "default" ||
Expand Down Expand Up @@ -377,6 +388,7 @@ ManageIQ.angular.app.controller('emsCommonFormController', ['$http', '$scope', '
};

$scope.providerTypeChanged = function() {
$scope.updateProviderOptionsDescription();
if ($scope.emsCommonModel.ems_controller === 'ems_container') {
if ($scope.emsCommonModel.emstype === 'kubernetes') {
$scope.emsCommonModel.default_api_port = "6443";
Expand Down Expand Up @@ -591,5 +603,54 @@ ManageIQ.angular.app.controller('emsCommonFormController', ['$http', '$scope', '
}
};

$scope.updateProviderOptionsDescription = function() {
API.options('/api/providers').then(function(response) {
$scope.setProviderOptionsDescription(response.data);
});
};

$scope.setProviderOptionsDescription = function(apiResponse) {
if (! apiResponse.hasOwnProperty("provider_settings")) return;
if (! apiResponse.provider_settings.hasOwnProperty($scope.emsCommonModel.emstype)) {
return;
}
$scope.emsOptionsModel.provider_options = apiResponse.provider_settings[$scope.emsCommonModel.emstype];
if ($scope.emsOptionsModel.provider_options.hasOwnProperty('advanced_settings')) {
var advanced_settings = $scope.emsOptionsModel.provider_options.advanced_settings.settings;
$scope.emsCommonModel.provider_options.advanced_settings = {};
for (var section in advanced_settings) {
if (advanced_settings.hasOwnProperty(section)) {
$scope.emsCommonModel.provider_options.advanced_settings[section] = {};
$scope.updateProviderOptionsOldValues(advanced_settings[section],
$scope.emsCommonModel.provider_options.advanced_settings[section]);
}
}
}
if ($scope.emsOptionsModel.provider_options.hasOwnProperty('proxy_settings')) {
$scope.emsCommonModel.provider_options.proxy_settings = {};
$scope.updateProviderOptionsOldValues($scope.emsOptionsModel.provider_options.proxy_settings,
$scope.emsCommonModel.provider_options.proxy_settings);
}
};

// Sets the values and names of the options in sourceSection and destSection from
// $scope.emsOptionsModel.provider_options_original_values if they exist there.
$scope.updateProviderOptionsOldValues = function(sourceSection, destSection) {
var section_name = _.snakeCase(sourceSection.label);
sourceSection.section_name = section_name;
for (var option in sourceSection.settings) {
if (sourceSection.settings.hasOwnProperty(option)) {
if ($scope.emsOptionsModel.provider_options_original_values.hasOwnProperty(section_name) &&
$scope.emsOptionsModel.provider_options_original_values[section_name].hasOwnProperty(option)) {
sourceSection.settings[option].value = $scope.emsOptionsModel.provider_options_original_values[section_name][option];
} else {
sourceSection.settings[option].value = "";
}
sourceSection.settings[option].name = option;
destSection[option] = sourceSection.settings[option];
}
}
};

init();
}]);
23 changes: 23 additions & 0 deletions app/controllers/mixins/ems_common_angular.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ def ems_form_fields
prometheus_alerts_security_protocol = security_protocol_default
prometheus_alerts_tls_ca_certs = ""

provider_options = @ems.options || {}

if @ems.connection_configurations.amqp.try(:endpoint)
amqp_hostname = @ems.connection_configurations.amqp.endpoint.hostname
amqp_port = @ems.connection_configurations.amqp.endpoint.port
Expand Down Expand Up @@ -361,6 +363,7 @@ def ems_form_fields
:prometheus_alerts_security_protocol => prometheus_alerts_security_protocol,
:prometheus_alerts_tls_ca_certs => prometheus_alerts_tls_ca_certs,
:prometheus_alerts_auth_status => prometheus_alerts_auth_status,
:provider_options => provider_options,
:alerts_selection => retrieve_alerts_selection}
end

Expand Down Expand Up @@ -513,6 +516,7 @@ def set_ems_record_vars(ems, mode = nil)
prometheus_endpoint = {:role => :prometheus, :hostname => metrics_hostname, :port => metrics_port}
prometheus_endpoint.merge!(endpoint_security_options(metrics_security_protocol, metrics_tls_ca_certs))
end

if params[:alerts_selection] == 'prometheus'
params[:cred_type] = "prometheus_alerts"
prometheus_alerts_endpoint = {:role => :prometheus_alerts, :hostname => prometheus_alerts_hostname, :port => prometheus_alerts_api_port}
Expand All @@ -538,6 +542,25 @@ def set_ems_record_vars(ems, mode = nil)
default_endpoint = {:role => :default, :hostname => hostname, :port => port}
end

new_options = {}
if ems.class.respond_to?(:advanced_settings)
ems.class.advanced_settings.each do |section_name, section|
section[:settings].each do |opt, _|
new_options[section_name.to_sym] ||= {}
value = params["provider_options_#{section_name}_#{opt}".to_sym]
new_options[section_name.to_sym][opt.to_sym] = value if value.present?
end
end
end
if ems.class.respond_to?(:proxy_settings)
new_options[:proxy_settings] = {}
ems.class.proxy_settings.each do |opt, _|
value = params["provider_options_proxy_settings_#{opt}".to_sym]
new_options[:proxy_settings][opt] = value if value.present?
end
end
ems.options = new_options

endpoints = {:default => default_endpoint,
:ceilometer => ceilometer_endpoint,
:amqp => amqp_endpoint,
Expand Down
10 changes: 5 additions & 5 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1540,10 +1540,7 @@ def title_for_cluster_record(record)

def miq_tab_header(id, active = nil, options = {}, &_block)
tag_options = {:class => "#{options[:class]} #{active == id ? 'active' : ''}",
:id => "#{id}_tab"}

tag_options['ng-click'] = options['ng-click'] if options.key?('ng-click')
tag_options[:onclick] = options[:onclick] if options.key?(:onclick)
:id => "#{id}_tab"}.merge!(options)

content_tag(:li, tag_options) do
content_tag(:a, :href => "##{id}", 'data-toggle' => 'tab') do
Expand All @@ -1560,7 +1557,10 @@ def miq_tab_content(id, active = nil, options = {}, &_block)
classname << 'active' if active == id
classname << 'lazy' if lazy

content_tag(:div, :id => id, :class => classname.join(' ')) do
options.delete(:lazy)
options.delete(:class)

content_tag(:div, :id => id, :class => classname.join(' '), **options) do
yield unless lazy
end
end
Expand Down
4 changes: 4 additions & 0 deletions app/views/ems_container/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,8 @@
%hr
= render :partial => "layouts/angular/multi_auth_credentials", :locals => {:record => @ems, :ng_model => "emsCommonModel"}
%div{"ng-if" => "emsOptionsModel.provider_options.hasOwnProperty('proxy_settings') || emsOptionsModel.provider_options.hasOwnProperty('advanced_settings')"}
%hr
= render :partial => "/layouts/angular/per_provider_settings"
= render :partial => "layouts/angular/x_edit_buttons_angular", :locals => {:record => @ems, :restful => true}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
%provider-option-section{"ng-repeat" => "section in emsOptionsModel.provider_options.advanced_settings.settings",
"label" => "{{ section.label }}",
"help_text" => "{{ section.help_text }}",
"section_name" => "{{ section.section_name }}",
"settings" => "section.settings"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
%provider-option-section{"label" => "{{ emsOptionsModel.provider_options.proxy_settings.label }}",
"help_text" => "{{ emsOptionsModel.provider_options.proxy_settings.help_text }}",
"section_name" => "{{ emsOptionsModel.provider_options.proxy_settings.section_name }}",
"settings" => "emsOptionsModel.provider_options.proxy_settings.settings"}
4 changes: 4 additions & 0 deletions app/views/layouts/angular/_multi_auth_credentials.html.haml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
- validate_url ||= (record.id || @selected_hosts) ? "update" : "create"
- legendtext ||= _("Endpoints")
- vm_scope ||= false
- main_scope = vm_scope ? "$parent.vm" : "$parent"


#auth_tabs
%h3
= legendtext
%ul.nav.nav-tabs
= miq_tab_header('default', nil, {'ng-click' => "changeAuthTab('default')"}) do
%i{"error-on-tab" => "default", :style => "color:#cc0000"}
Expand Down
25 changes: 25 additions & 0 deletions app/views/layouts/angular/_per_provider_settings.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#settings_tabs
%h3
= _("Settings")
%ul.nav.nav-tabs
= miq_tab_header('proxy_settings', nil, 'ng-click' => "changeAuthTab('proxy_settings')",
'ng-if' => "emsOptionsModel.provider_options.hasOwnProperty('proxy_settings')") do
%i{"error-on-tab" => "proxy_settings", :style => "color:#cc0000"}
= _("Proxy")
= miq_tab_header('advanced_settings', nil, 'ng-click' => "changeAuthTab('advanced_settings')",
'ng-if' => "emsOptionsModel.provider_options.hasOwnProperty('advanced_settings')") do
%i{"error-on-tab" => "advanced_settings", :style => "color:#cc0000"}
= _("Advanced")

.tab-content
= miq_tab_content('proxy_settings', 'proxy_settings', "ng-if".to_sym => "emsOptionsModel.provider_options.hasOwnProperty('proxy_settings')") do
.form-group
.col-md-12.col-md-12
= render :partial => "layouts/angular-bootstrap/provider_proxy_settings"
= miq_tab_content('advanced_settings', 'proxy_settings', "ng-if".to_sym => "emsOptionsModel.provider_options.hasOwnProperty('advanced_settings')") do
.form-group
.col-md-12.col-md-12
= render :partial => "layouts/angular-bootstrap/provider_advanced_settings"

:javascript
miq_tabs_init('#settings_tabs');
15 changes: 15 additions & 0 deletions app/views/static/provider_option_field_input.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.form-group{"ng-class" => "{{ \"{'has_error': angularForm.\" + $ctrl.elemID + \".$invalid}\" }}"}
%label.col-md-2.control-label{"for" => "{{ $ctrl.elemID }}"}
{{ $ctrl.option.label }}
.col-md-4
%input.form-control{"type" => "text",
"id" => "{{ $ctrl.elemID }}",
"name" => "{{ $ctrl.elemID }}",
"ng-model" => "$ctrl.option.value",
"ng-trim" => false,
"detect_spaces" => "",
"placeholder" => "{{ $ctrl.option.global_default }}",
"title" => "{{ $ctrl.option.help_text }}",
"prefix" => "{{ 'provider_options_' + $ctrl.sectionName }}"}
%span.help-block{"ng-show" => '{{ "angularForm." + $ctrl.elemID + ".$error.detectedSpaces" }}'}
= _("Spaces are prohibited")
3 changes: 3 additions & 0 deletions app/views/static/provider_option_section.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
%provider-option-field-input{"ng-repeat" => "option in $ctrl.settings",
"option" => "option",
"section-name" => "{{ $ctrl.sectionName }}"}
9 changes: 9 additions & 0 deletions spec/controllers/ems_common_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,15 @@ def test_setting_few_fields
test_setting_few_fields
expect(@ems.connection_configurations.hawkular.endpoint.hostname).to eq('10.10.10.10')
end

it 'updates provider options' do
@type = 'openshift'
@ems = ManageIQ::Providers::Openshift::ContainerManager.new
controller.instance_variable_set(:@_params,
:provider_options_image_inspector_options_http_proxy => "example.com")
controller.send(:set_ems_record_vars, @ems)
expect(@ems.options[:image_inspector_options][:http_proxy]).to eq("example.com")
end
end
end

Expand Down
31 changes: 31 additions & 0 deletions spec/controllers/ems_container_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,37 @@
end
end

describe "create with provider options" do
let(:zone) { FactoryGirl.build(:zone) }
let!(:server) { EvmSpecHelper.local_miq_server(:zone => zone) }

before do
allow(controller).to receive(:check_privileges).and_return(true)
allow(controller).to receive(:assert_privileges).and_return(true)
end

it "Creates a provider with provider options" do
params = {
"button" => "add",
"name" => "openshift_no_hawkular",
"emstype" => "openshift",
"zone" => 'default',
"default_security_protocol" => "ssl-without-validation",
"default_hostname" => "default_hostname",
"default_api_port" => "5000",
"default_userid" => "",
"default_password" => "",
"provider_region" => "",
"metrics_selection" => "hawkular_disabled",
}
params["provider_options_image_inspector_options_http_proxy"] = "hello.com"
post :create, :params => params
expect(response.status).to eq(200)
ems_openshift = ManageIQ::Providers::ContainerManager.first
expect(ems_openshift.options[:image_inspector_options][:http_proxy]).to eq("hello.com")
end
end

describe "Hawkular Disabled/Enabled" do
let(:zone) { FactoryGirl.build(:zone) }
let!(:server) { EvmSpecHelper.local_miq_server(:zone => zone) }
Expand Down
Loading

0 comments on commit ab3f23e

Please sign in to comment.