fix adhoc command cred lookup when many credential types exist

This commit is contained in:
Jake McDermott
2018-11-06 22:36:14 -05:00
parent 0f85c867a0
commit ceb9bfe486
2 changed files with 21 additions and 13 deletions

View File

@@ -12,7 +12,7 @@
function adhocController($q, $scope, $stateParams, function adhocController($q, $scope, $stateParams,
$state, CheckPasswords, PromptForPasswords, CreateLaunchDialog, CreateSelect2, adhocForm, $state, CheckPasswords, PromptForPasswords, CreateLaunchDialog, CreateSelect2, adhocForm,
GenerateForm, Rest, ProcessErrors, GetBasePath, GetChoices, GenerateForm, Rest, ProcessErrors, GetBasePath, GetChoices,
KindChange, Wait, ParseTypeChange, credentialTypes) { KindChange, Wait, ParseTypeChange, machineCredentialType) {
// this is done so that we can access private functions for testing, but // this is done so that we can access private functions for testing, but
// we don't want to populate the "public" scope with these internal // we don't want to populate the "public" scope with these internal
@@ -302,12 +302,9 @@ function adhocController($q, $scope, $stateParams,
}; };
$scope.lookupCredential = function(){ $scope.lookupCredential = function(){
let credType = _.filter(credentialTypes, function(credType){
return credType.kind === "ssh";
});
$state.go('.credential', { $state.go('.credential', {
credential_search: { credential_search: {
credential_type: credType[0].id, credential_type: machineCredentialType,
page_size: '5', page_size: '5',
page: '1' page: '1'
} }
@@ -319,5 +316,5 @@ function adhocController($q, $scope, $stateParams,
export default ['$q', '$scope', '$stateParams', export default ['$q', '$scope', '$stateParams',
'$state', 'CheckPasswords', 'PromptForPasswords', 'CreateLaunchDialog', 'CreateSelect2', '$state', 'CheckPasswords', 'PromptForPasswords', 'CreateLaunchDialog', 'CreateSelect2',
'adhocForm', 'GenerateForm', 'Rest', 'ProcessErrors', 'GetBasePath', 'adhocForm', 'GenerateForm', 'Rest', 'ProcessErrors', 'GetBasePath',
'GetChoices', 'KindChange', 'Wait', 'ParseTypeChange', 'credentialTypes', 'GetChoices', 'KindChange', 'Wait', 'ParseTypeChange', 'machineCredentialType',
adhocController]; adhocController];

View File

@@ -7,6 +7,23 @@
import {templateUrl} from '../../../shared/template-url/template-url.factory'; import {templateUrl} from '../../../shared/template-url/template-url.factory';
import { N_ } from '../../../i18n'; import { N_ } from '../../../i18n';
function ResolveMachineCredentialType (GetBasePath, Rest, ProcessErrors) {
Rest.setUrl(GetBasePath('credential_types') + '?kind=ssh');
return Rest.get()
.then(({ data }) => {
return data.results[0].id;
})
.catch(({ data, status }) => {
ProcessErrors(null, data, status, null, {
hdr: 'Error!',
msg: 'Failed to get credential type data: ' + status
});
});
}
ResolveMachineCredentialType.$inject = ['GetBasePath', 'Rest', 'ProcessErrors'];
export default { export default {
url: '/adhoc', url: '/adhoc',
params:{ params:{
@@ -28,12 +45,6 @@ export default {
label: N_("RUN COMMAND") label: N_("RUN COMMAND")
}, },
resolve: { resolve: {
credentialTypes: ['CredentialTypeModel', (CredentialType) => machineCredentialType: ResolveMachineCredentialType,
new CredentialType('get')
.then((model) => {
const credentialTypeRes = model.get();
return credentialTypeRes.results;
})
]
} }
}; };