Skip to content

Commit

Permalink
Refactor getting the credential list
Browse files Browse the repository at this point in the history
  • Loading branch information
lgalis committed Feb 28, 2018
1 parent 18383c3 commit 481744e
Showing 1 changed file with 18 additions and 25 deletions.
43 changes: 18 additions & 25 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(credentialUrl, type, 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['_' + prefix + type + '_credential'] = _.find(vm[type + '_credentials'], {id: vm[vm.model]['prefix' + '_' + type + '_credential_id']});
}
})
.catch(miqService.handleFailure)
);
};

// list of service catalogs
var formOptions = function(vm) {
miqService.sparkleOn();
Expand Down Expand Up @@ -134,34 +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 machine credentials
allApiPromises.push(API.get('/api/authentications?collection_class=ManageIQ::Providers::EmbeddedAnsible::AutomationManager::VaultCredential&expand=resources&attributes=id,name' + sortOptions)
.then(function(data) {
vm.vault_credentials = data.resources;
vm._vault_credential = _.find(vm.vault_credentials, {id: vm[vm.model].retirement_vault_credential_id});
vm._provisioning_vault_credential = _.find(vm.vault_credentials, {id: vm[vm.model].provisioning_vault_credential_id});
})
.catch(miqService.handleFailure)
);
// 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

0 comments on commit 481744e

Please sign in to comment.