Skip to content

Commit

Permalink
Refactors ansible credentials to treat dialog object as override
Browse files Browse the repository at this point in the history
Also displays any config_info credential object with 'credential' in the key
  • Loading branch information
AllenBW committed Apr 4, 2018
1 parent 0ae3d01 commit 3e6aae1
Showing 1 changed file with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ function ComponentController (ModalService, ServicesState, lodash) {

function fetchResources () {
vm.loading = true
const credentialTypes = ['credential_id', 'network_credential_id', 'machine_credential_id', 'cloud_credential_id']

if (angular.isDefined(vm.service.options.config_info)) {
vm.orcStacks = {}
Expand All @@ -47,16 +46,23 @@ function ComponentController (ModalService, ServicesState, lodash) {
vm.orcStacks[resourceName] = {}
vm.orcStacks[resourceName].stack = lodash.find(vm.service.orchestration_stacks, {'id': resource.resource_id})
vm.orcStacks[resourceName].resource = resource

vm.orcStacks[resourceName].credentials = []
credentialTypes.forEach((credential) => {
if (angular.isDefined(vm.service.options.config_info[resourceName][credential])) {
ServicesState.getServiceCredential(vm.service.options.config_info[resourceName][credential]).then((response) => {
response.type = response.type.substring(response.type.lastIndexOf('::') + 2, response.type.lastIndexOf('Credential'))
vm.orcStacks[resourceName].credentials.push(response)

if (vm.service.options.dialog && resourceName === 'provision') {
Object.assign(
vm.service.options.config_info[resourceName],
...Object.keys(vm.service.options.dialog)
.map(key => ({[normalizeDialogKeys(key)]: vm.service.options.dialog[key]}))
)
}

for (const configItem in vm.service.options.config_info[resourceName]) {
if (configItem.includes('credential')) {
ServicesState.getServiceCredential(vm.service.options.config_info[resourceName][configItem]).then((response) => {
vm.orcStacks[resourceName].credentials.push(processCredential(response))
})
}
})
}

ServicesState.getServiceRepository(vm.service.options.config_info[resourceName].repository_id).then((response) => {
vm.orcStacks[resourceName].repository = response
Expand Down Expand Up @@ -106,4 +112,15 @@ function ComponentController (ModalService, ServicesState, lodash) {
function elapsed (finish, start) {
return Math.abs(new Date(finish) - new Date(start)) / 1000
}

function processCredential (item) {
item.type = item.type.substring(item.type.lastIndexOf('::') + 2, item.type.lastIndexOf('Credential'))
return item
}

function normalizeDialogKeys (key) {
const normalizedKey = key.replace(/dialog_/i, '')

return normalizedKey === 'credential' ? 'credential_id' : normalizedKey
}
}

0 comments on commit 3e6aae1

Please sign in to comment.