Skip to content

Commit

Permalink
Merge pull request #3468 from lgalis/vault_credentials_for_embedded_a…
Browse files Browse the repository at this point in the history
…nsible

Add Vault credentials to the UI for Embedded Ansible
  • Loading branch information
h-kataria authored Mar 23, 2018
2 parents b3adc09 + 774c9fe commit 3ba4962
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ ManageIQ.angular.app.controller('catalogItemFormController', ['$scope', 'catalog
provisioning_machine_credential_id: '',
provisioning_network_credential_id: '',
provisioning_cloud_credential_id: '',
provisioning_vault_credential_id: '',
provisioning_execution_ttl: '',
provisioning_inventory: 'localhost',
provisioning_dialog_existing: '',
Expand All @@ -31,6 +32,7 @@ ManageIQ.angular.app.controller('catalogItemFormController', ['$scope', 'catalog
retirement_machine_credential_id: '',
retirement_network_credential_id: '',
retirement_cloud_credential_id: '',
retirement_vault_credential_id: '',
retirement_execution_ttl: '',
retirement_inventory: 'localhost',
retirement_key: '',
Expand Down Expand Up @@ -82,6 +84,7 @@ ManageIQ.angular.app.controller('catalogItemFormController', ['$scope', 'catalog
vm.catalogItemModel.provisioning_machine_credential_id = configData.provision.credential_id;
vm.catalogItemModel.provisioning_network_credential_id = configData.provision.network_credential_id;
vm.catalogItemModel.provisioning_cloud_credential_id = playbookReusableCodeMixin.setIfDefined(configData.provision.cloud_credential_id);
vm.catalogItemModel.provisioning_vault_credential_id = playbookReusableCodeMixin.setIfDefined(configData.provision.vault_credential_id);
vm.catalogItemModel.provisioning_execution_ttl = configData.provision.execution_ttl;
vm.catalogItemModel.provisioning_inventory = configData.provision.hosts;
if (configData.provision.hosts !== 'localhost') {
Expand Down Expand Up @@ -115,6 +118,7 @@ ManageIQ.angular.app.controller('catalogItemFormController', ['$scope', 'catalog
playbookReusableCodeMixin.getRemoveResourcesTypes(vm);
vm.catalogItemModel.retirement_remove_resources = configData.retirement.remove_resources;
vm.catalogItemModel.retirement_machine_credential_id = configData.retirement.credential_id;
vm.catalogItemModel.retirement_vault_credential_id = configData.retirement.vault_credential_id;
}
if (configData.retirement.become_enabled === undefined) {
vm.catalogItemModel.retirement_become_enabled = false;
Expand All @@ -129,6 +133,7 @@ ManageIQ.angular.app.controller('catalogItemFormController', ['$scope', 'catalog
}

vm.catalogItemModel.retirement_network_credential_id = configData.retirement.network_credential_id;
vm.catalogItemModel.retirement_vault_credential_id = playbookReusableCodeMixin.setIfDefined(configData.retirement.vault_credential_id);
vm.catalogItemModel.retirement_cloud_credential_id = playbookReusableCodeMixin.setIfDefined(configData.retirement.cloud_credential_id);
vm.catalogItemModel.retirement_execution_ttl = configData.retirement.execution_ttl;
vm.catalogItemModel.retirement_inventory = configData.retirement.hosts;
Expand Down Expand Up @@ -224,6 +229,9 @@ ManageIQ.angular.app.controller('catalogItemFormController', ['$scope', 'catalog
catalog_item['config_info']['provision']['execution_ttl'] = configData.provisioning_execution_ttl;
}
catalog_item['config_info']['provision']['become_enabled'] = configData.provisioning_become_enabled;
if (configData.provisioning_vault_credential_id !== '') {
catalog_item['config_info']['provision']['vault_credential_id'] = configData.provisioning_vault_credential_id;
}
if (configData.provisioning_network_credential_id !== '') {
catalog_item['config_info']['provision']['network_credential_id'] = configData.provisioning_network_credential_id;
}
Expand Down Expand Up @@ -255,6 +263,9 @@ ManageIQ.angular.app.controller('catalogItemFormController', ['$scope', 'catalog
retirement['extra_vars'] = formatExtraVars(configData.retirement_variables);
catalog_item['config_info']['retirement']['become_enabled'] = configData.retirement_become_enabled;
}
if (configData.retirement_vault_credential_id !== '')
catalog_item['config_info']['retirement']['vault_credential_id'] = configData.retirement_vault_credential_id;

if (configData.retirement_network_credential_id !== '')
catalog_item['config_info']['retirement']['network_credential_id'] = configData.retirement_network_credential_id;

Expand Down Expand Up @@ -393,19 +404,17 @@ ManageIQ.angular.app.controller('catalogItemFormController', ['$scope', 'catalog
};

// watch for all the drop downs on screen
'catalog provisioning_playbook retirement_playbook provisioning_machine_credential retirement_machine_credential provisioning_network_credential retirement_network_credential provisioning_cloud_credential retirement_cloud_credential provisioning_dialog'.split(' ').forEach(idWatch);
'catalog provisioning_playbook retirement_playbook provisioning_machine_credential retirement_machine_credential provisioning_vault_credential retirement_vault_credential provisioning_network_credential retirement_network_credential provisioning_cloud_credential retirement_cloud_credential provisioning_dialog'.split(' ').forEach(idWatch);

function idWatch(name) {
var fieldName = 'vm._' + name;
$scope.$watch(fieldName, function(value) {
if (value) {
vm.catalogItemModel[name + '_id'] = value.id;
}
vm.catalogItemModel[name + '_id'] = value ? value.id : '';
playbookReusableCodeMixin.checkFormPristine(vm.catalogItemModel, vm.modelCopy, $scope.angularForm);
});
}

// watch for all the drop downs on screen
// watch for all the drop downs on screen
'retirement_remove_resources'.split(' ').forEach(typeWatch);

function typeWatch(name) {
Expand All @@ -429,6 +438,7 @@ ManageIQ.angular.app.controller('catalogItemFormController', ['$scope', 'catalog
vm.catalogItemModel.retirement_playbook_id = vm.catalogItemModel.provisioning_playbook_id;
vm.catalogItemModel.retirement_machine_credential_id = vm.catalogItemModel.provisioning_machine_credential_id;
vm.catalogItemModel.retirement_network_credential_id = vm.catalogItemModel.provisioning_network_credential_id;
vm.catalogItemModel.retirement_vault_credential_id = vm.catalogItemModel.provisioning_vault_credential_id;
vm.retirement_cloud_type = vm.provisioning_cloud_type;
vm._retirement_cloud_type = vm.provisioning_cloud_type;
vm.catalogItemModel.retirement_cloud_credential_id = vm.catalogItemModel.provisioning_cloud_credential_id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function aeMethodFormController($http, $scope, aeMethodFormId, currentRegion, mi
provisioning_machine_credential_id: '',
provisioning_network_credential_id: '',
provisioning_cloud_credential_id: '',
provisioning_vault_credential_id: '',
provisioning_key: '',
provisioning_value: '',
provisioning_type: 'string',
Expand Down Expand Up @@ -74,6 +75,7 @@ function aeMethodFormController($http, $scope, aeMethodFormId, currentRegion, mi
vm.aeMethodModel.provisioning_playbook_id = configData.playbook_id;
vm.aeMethodModel.provisioning_machine_credential_id = configData.credential_id;
vm.aeMethodModel.provisioning_network_credential_id = configData.network_credential_id;
vm.aeMethodModel.provisioning_vault_credential_id = configData.vault_credential_id;
vm.aeMethodModel.provisioning_cloud_credential_id = playbookReusableCodeMixin.setIfDefined(configData.cloud_credential_id);
vm.aeMethodModel.provisioning_become_enabled = configData.become_enabled === true;
vm.aeMethodModel.provisioning_key = '';
Expand Down Expand Up @@ -108,6 +110,7 @@ function aeMethodFormController($http, $scope, aeMethodFormId, currentRegion, mi
vm.aeMethodModel = angular.copy(vm.modelCopy);
playbookReusableCodeMixin.formOptions(vm);
playbookReusableCodeMixin.cloudCredentialsList(vm, vm.aeMethodModel.provisioning_cloud_credential_id);
playbookReusableCodeMixin.checkFormDataRetrieval(vm);
$scope.angularForm.$setUntouched(true);
$scope.angularForm.$setPristine(true);
miqService.miqFlash("warn", __("All changes have been reset"));
Expand Down Expand Up @@ -143,6 +146,7 @@ function aeMethodFormController($http, $scope, aeMethodFormId, currentRegion, mi
repository_id: configData.provisioning_repository_id,
playbook_id: configData.provisioning_playbook_id,
credential_id: configData.provisioning_machine_credential_id,
vault_credential_id: configData.provisioning_vault_credential_id,
verbosity: configData.provisioning_verbosity,
become_enabled: configData.provisioning_become_enabled,
execution_ttl: configData.provisioning_execution_ttl,
Expand Down Expand Up @@ -259,14 +263,12 @@ function aeMethodFormController($http, $scope, aeMethodFormId, currentRegion, mi
};

// watch for all the drop downs on screen
"provisioning_playbook provisioning_machine_credential provisioning_network_credential provisioning_cloud_credential".split(" ").forEach(idWatch);
"provisioning_playbook provisioning_machine_credential provisioning_vault_credential provisioning_network_credential provisioning_cloud_credential".split(" ").forEach(idWatch);

function idWatch(name) {
var fieldName = "vm._" + name;
$scope.$watch(fieldName, function(value) {
if (value) {
vm.aeMethodModel[name + '_id'] = value.id;
}
vm.aeMethodModel[name + '_id'] = value ? value.id : '';
playbookReusableCodeMixin.checkFormPristine(vm.aeMethodModel, vm.modelCopy, $scope.angularForm);
});
}
Expand Down
35 changes: 19 additions & 16 deletions app/assets/javascripts/controllers/playbook-reusable-code-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,20 @@ function playbookReusableCodeMixin(API, $q, miqService) {
);
};

var getCredentialsForType = function(type, credentialUrl, vm) {
var prefixes = ['retirement', 'provisioning'];
var prefixLen = prefixes.length;
allApiPromises.push(API.get(credentialUrl + sortOptions)
.then(function(data) {
vm[type + '_credentials'] = data.resources;
for (var i = 0; i < prefixLen; i++) {
vm['_' + prefixes[i] + '_' + type + '_credential'] = _.find(vm[type + '_credentials'], {id: vm[vm.model][prefixes[i] + '_' + type + '_credential_id']});
}
})
.catch(miqService.handleFailure)
);
};

// list of service catalogs
var formOptions = function(vm) {
miqService.sparkleOn();
Expand Down Expand Up @@ -134,24 +148,13 @@ function playbookReusableCodeMixin(API, $q, miqService) {
);

// list of machine credentials
allApiPromises.push(API.get('/api/authentications?collection_class=ManageIQ::Providers::EmbeddedAnsible::AutomationManager::MachineCredential&expand=resources&attributes=id,name' + sortOptions)
.then(function(data) {
vm.machine_credentials = data.resources;
vm._retirement_machine_credential = _.find(vm.machine_credentials, {id: vm[vm.model].retirement_machine_credential_id});
vm._provisioning_machine_credential = _.find(vm.machine_credentials, {id: vm[vm.model].provisioning_machine_credential_id});
})
.catch(miqService.handleFailure)
);
getCredentialsForType('machine', '/api/authentications?collection_class=ManageIQ::Providers::EmbeddedAnsible::AutomationManager::MachineCredential&expand=resources&attributes=id,name', vm);

// list of vault credentials
getCredentialsForType('vault', '/api/authentications?collection_class=ManageIQ::Providers::EmbeddedAnsible::AutomationManager::VaultCredential&expand=resources&attributes=id,name', vm);

// list of network credentials
allApiPromises.push(API.get('/api/authentications?collection_class=ManageIQ::Providers::EmbeddedAnsible::AutomationManager::NetworkCredential&expand=resources&attributes=id,name' + sortOptions)
.then(function(data) {
vm.network_credentials = data.resources;
vm._retirement_network_credential = _.find(vm.network_credentials, {id: vm[vm.model].retirement_network_credential_id});
vm._provisioning_network_credential = _.find(vm.network_credentials, {id: vm[vm.model].provisioning_network_credential_id});
})
.catch(miqService.handleFailure)
);
getCredentialsForType('network', '/api/authentications?collection_class=ManageIQ::Providers::EmbeddedAnsible::AutomationManager::NetworkCredential&expand=resources&attributes=id,name', vm);
};

function retrievedFormData(vm) {
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1865,6 +1865,7 @@ def fetch_playbook_details
playbook_details[:provisioning][:machine_credential] = fetch_name_from_object(ManageIQ::Providers::EmbeddedAnsible::AutomationManager::MachineCredential, provision[:credential_id])
playbook_details[:provisioning][:network_credential] = fetch_name_from_object(ManageIQ::Providers::EmbeddedAnsible::AutomationManager::NetworkCredential, provision[:network_credential_id]) if provision[:network_credential_id]
playbook_details[:provisioning][:cloud_credential] = fetch_name_from_object(ManageIQ::Providers::EmbeddedAnsible::AutomationManager::CloudCredential, provision[:cloud_credential_id]) if provision[:cloud_credential_id]
playbook_details[:provisioning][:vault_credential] = fetch_name_from_object(ManageIQ::Providers::EmbeddedAnsible::AutomationManager::VaultCredential, provision[:vault_credential_id]) if provision[:vault_credential_id]
fetch_dialog(playbook_details, provision[:dialog_id], :provisioning)
playbook_details[:provisioning][:execution_ttl] = provision[:execution_ttl]
playbook_details[:provisioning][:verbosity] = provision[:verbosity]
Expand All @@ -1881,6 +1882,7 @@ def fetch_playbook_details
playbook_details[:retirement][:machine_credential] = fetch_name_from_object(ManageIQ::Providers::EmbeddedAnsible::AutomationManager::MachineCredential, retirement[:credential_id])
playbook_details[:retirement][:network_credential] = fetch_name_from_object(ManageIQ::Providers::EmbeddedAnsible::AutomationManager::NetworkCredential, retirement[:network_credential_id]) if retirement[:network_credential_id]
playbook_details[:retirement][:cloud_credential] = fetch_name_from_object(ManageIQ::Providers::EmbeddedAnsible::AutomationManager::CloudCredential, retirement[:cloud_credential_id]) if retirement[:cloud_credential_id]
playbook_details[:retirement][:vault_credential] = fetch_name_from_object(ManageIQ::Providers::EmbeddedAnsible::AutomationManager::VaultCredential, retirement[:vault_credential_id]) if retirement[:vault_credential_id]
end
playbook_details[:retirement][:execution_ttl] = retirement[:execution_ttl]
playbook_details[:retirement][:verbosity] = retirement[:verbosity]
Expand Down
27 changes: 14 additions & 13 deletions app/controllers/miq_ae_class_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -985,19 +985,18 @@ def method_form_fields
:language => 'ruby',
:scope => "instance",
:available_datatypes => MiqAeField.available_datatypes_for_ui,
:config_info => {
:repository_id => method.options[:repository_id] || '',
:playbook_id => method.options[:playbook_id] || '',
:credential_id => method.options[:credential_id] || '',
:network_credential_id => method.options[:network_credential_id] || '',
:cloud_credential_id => method.options[:cloud_credential_id] || '',
:verbosity => method.options[:verbosity],
:become_enabled => method.options[:become_enabled] || false,
:execution_ttl => method.options[:execution_ttl] || '',
:hosts => method.options[:hosts] || 'localhost',
:log_output => method.options[:log_output] || 'on_error',
:extra_vars => method.inputs
}
:config_info => { :repository_id => method.options[:repository_id] || '',
:playbook_id => method.options[:playbook_id] || '',
:credential_id => method.options[:credential_id] || '',
:vault_credential_id => method.options[:vault_credential_id] || '',
:network_credential_id => method.options[:network_credential_id] || '',
:cloud_credential_id => method.options[:cloud_credential_id] || '',
:verbosity => method.options[:verbosity],
:become_enabled => method.options[:become_enabled] || false,
:execution_ttl => method.options[:execution_ttl] || '',
:hosts => method.options[:hosts] || 'localhost',
:log_output => method.options[:log_output] || 'on_error',
:extra_vars => method.inputs }
}
render :json => method_hash
end
Expand Down Expand Up @@ -1749,6 +1748,7 @@ def set_playbook_data
params_list = %i(repository_id
playbook_id
credential_id
vault_credential_id
verbosity
network_credential_id
cloud_credential_id
Expand Down Expand Up @@ -2709,6 +2709,7 @@ def fetch_playbook_details
@playbook_details[:machine_credential] = fetch_name_from_object(ManageIQ::Providers::EmbeddedAnsible::AutomationManager::MachineCredential, options[:credential_id])
@playbook_details[:network_credential] = fetch_name_from_object(ManageIQ::Providers::EmbeddedAnsible::AutomationManager::NetworkCredential, options[:network_credential_id]) if options[:network_credential_id]
@playbook_details[:cloud_credential] = fetch_name_from_object(ManageIQ::Providers::EmbeddedAnsible::AutomationManager::CloudCredential, options[:cloud_credential_id]) if options[:cloud_credential_id]
@playbook_details[:vault_credential] = fetch_name_from_object(ManageIQ::Providers::EmbeddedAnsible::AutomationManager::VaultCredential, options[:vault_credential_id]) if options[:vault_credential_id]
@playbook_details[:verbosity] = options[:verbosity]
@playbook_details[:become_enabled] = options[:become_enabled] == true ? _("Yes") : _("No")
@playbook_details[:execution_ttl] = options[:execution_ttl]
Expand Down
Loading

0 comments on commit 3ba4962

Please sign in to comment.