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
No known key found for this signature in database
GPG Key ID: 9A6F084352C3A0B7
2 changed files with 21 additions and 13 deletions

View File

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

View File

@ -7,6 +7,23 @@
import {templateUrl} from '../../../shared/template-url/template-url.factory';
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 {
url: '/adhoc',
params:{
@ -28,12 +45,6 @@ export default {
label: N_("RUN COMMAND")
},
resolve: {
credentialTypes: ['CredentialTypeModel', (CredentialType) =>
new CredentialType('get')
.then((model) => {
const credentialTypeRes = model.get();
return credentialTypeRes.results;
})
]
machineCredentialType: ResolveMachineCredentialType,
}
};