diff --git a/awx/ui/client/src/inventories-hosts/inventories/adhoc/adhoc.controller.js b/awx/ui/client/src/inventories-hosts/inventories/adhoc/adhoc.controller.js index 0d98739305..45e18e5f38 100644 --- a/awx/ui/client/src/inventories-hosts/inventories/adhoc/adhoc.controller.js +++ b/awx/ui/client/src/inventories-hosts/inventories/adhoc/adhoc.controller.js @@ -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]; diff --git a/awx/ui/client/src/inventories-hosts/inventories/adhoc/adhoc.route.js b/awx/ui/client/src/inventories-hosts/inventories/adhoc/adhoc.route.js index 30d1f400a5..81ef6fa4c9 100644 --- a/awx/ui/client/src/inventories-hosts/inventories/adhoc/adhoc.route.js +++ b/awx/ui/client/src/inventories-hosts/inventories/adhoc/adhoc.route.js @@ -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, } };