From 2f57a1ea93cd2f805e552205f769d605ed8a9eee Mon Sep 17 00:00:00 2001 From: Jake McDermott Date: Thu, 6 Jun 2019 10:16:44 -0400 Subject: [PATCH] update inventory source credential lookup queries for api v2 --- .../sources/add/sources-add.controller.js | 47 ++++++++++++------- .../sources/edit/sources-edit.controller.js | 47 ++++++++++++------- .../lookup/sources-lookup-credential.route.js | 2 +- 3 files changed, 59 insertions(+), 37 deletions(-) diff --git a/awx/ui/client/src/inventories-hosts/inventories/related/sources/add/sources-add.controller.js b/awx/ui/client/src/inventories-hosts/inventories/related/sources/add/sources-add.controller.js index 72bdc53d5e..9e254fd7e5 100644 --- a/awx/ui/client/src/inventories-hosts/inventories/related/sources/add/sources-add.controller.js +++ b/awx/ui/client/src/inventories-hosts/inventories/related/sources/add/sources-add.controller.js @@ -133,25 +133,36 @@ export default ['$state', 'ConfigData', '$scope', 'SourcesFormDefinition', 'Pars }); $scope.lookupCredential = function(){ - if($scope.source.value !== "scm" && $scope.source.value !== "custom") { - let kind = ($scope.source.value === "ec2") ? "aws" : $scope.source.value; - $state.go('.credential', { - credential_search: { - kind: kind, - page_size: '5', - page: '1' - } - }); + // For most source type selections, we filter for 1-1 matches to credential_type namespace. + let searchKey = 'credential_type__namespace'; + let searchValue = $scope.source.value; + + // SCM and custom source types are more generic in terms of the credentials they + // accept - any cloud or user-defined credential type can be used. We filter for + // these using the credential_type kind field, which categorizes all cloud and + // user-defined credentials as 'cloud'. + if ($scope.source.value === 'scm') { + searchKey = 'credential_type__kind'; + searchValue = 'cloud'; } - else { - $state.go('.credential', { - credential_search: { - credential_type__kind: "cloud", - page_size: '5', - page: '1' - } - }); + + if ($scope.source.value === 'custom') { + searchKey = 'credential_type__kind'; + searchValue = 'cloud'; } + + // When the selection is 'ec2' we actually want to filter for the 'aws' namespace. + if ($scope.source.value === 'ec2') { + searchValue = 'aws'; + } + + $state.go('.credential', { + credential_search: { + [searchKey]: searchValue, + page_size: '5', + page: '1' + } + }); }; $scope.lookupProject = function(){ @@ -169,7 +180,7 @@ export default ['$state', 'ConfigData', '$scope', 'SourcesFormDefinition', 'Pars $scope.credentialBasePath = GetBasePath('credentials') + '?credential_type__kind__in=cloud,network'; } else{ - $scope.credentialBasePath = (source === 'ec2') ? GetBasePath('credentials') + '?kind=aws' : GetBasePath('credentials') + (source === '' ? '' : '?kind=' + (source)); + $scope.credentialBasePath = (source === 'ec2') ? GetBasePath('credentials') + '?credential_type__namespace=aws' : GetBasePath('credentials') + (source === '' ? '' : '?credential_type__namespace=' + (source)); } if (source === 'ec2' || source === 'custom' || source === 'vmware' || source === 'openstack' || source === 'scm' || source === 'cloudforms' || source === "satellite6" || source === "azure_rm") { $scope.envParseType = 'yaml'; diff --git a/awx/ui/client/src/inventories-hosts/inventories/related/sources/edit/sources-edit.controller.js b/awx/ui/client/src/inventories-hosts/inventories/related/sources/edit/sources-edit.controller.js index 33fa44f301..6096e1c84c 100644 --- a/awx/ui/client/src/inventories-hosts/inventories/related/sources/edit/sources-edit.controller.js +++ b/awx/ui/client/src/inventories-hosts/inventories/related/sources/edit/sources-edit.controller.js @@ -302,25 +302,36 @@ export default ['$state', '$scope', 'ParseVariableString', 'ParseTypeChange', }; $scope.lookupCredential = function(){ - if($scope.source.value !== "scm" && $scope.source.value !== "custom") { - let kind = ($scope.source.value === "ec2") ? "aws" : $scope.source.value; - $state.go('.credential', { - credential_search: { - kind: kind, - page_size: '5', - page: '1' - } - }); + // For most source type selections, we filter for 1-1 matches to credential_type namespace. + let searchKey = 'credential_type__namespace'; + let searchValue = $scope.source.value; + + // SCM and custom source types are more generic in terms of the credentials they + // accept - any cloud or user-defined credential type can be used. We filter for + // these using the credential_type kind field, which categorizes all cloud and + // user-defined credentials as 'cloud'. + if ($scope.source.value === 'scm') { + searchKey = 'credential_type__kind'; + searchValue = 'cloud'; } - else { - $state.go('.credential', { - credential_search: { - credential_type__kind: "cloud", - page_size: '5', - page: '1' - } - }); + + if ($scope.source.value === 'custom') { + searchKey = 'credential_type__kind'; + searchValue = 'cloud'; } + + // When the selection is 'ec2' we actually want to filter for the 'aws' namespace. + if ($scope.source.value === 'ec2') { + searchValue = 'aws'; + } + + $state.go('.credential', { + credential_search: { + [searchKey]: searchValue, + page_size: '5', + page: '1' + } + }); }; $scope.formCancel = function() { @@ -384,7 +395,7 @@ export default ['$state', '$scope', 'ParseVariableString', 'ParseTypeChange', $scope.credentialBasePath = GetBasePath('credentials') + '?credential_type__kind__in=cloud,network'; } else{ - $scope.credentialBasePath = (source === 'ec2') ? GetBasePath('credentials') + '?kind=aws' : GetBasePath('credentials') + (source === '' ? '' : '?kind=' + (source)); + $scope.credentialBasePath = (source === 'ec2') ? GetBasePath('credentials') + '?credential_type__namespace=aws' : GetBasePath('credentials') + (source === '' ? '' : 'credential_type__namespace=' + (source)); } if (source === 'ec2' || source === 'custom' || source === 'vmware' || source === 'openstack' || source === 'scm' || source === 'cloudforms' || source === "satellite6") { $scope.envParseType = 'yaml'; diff --git a/awx/ui/client/src/inventories-hosts/inventories/related/sources/lookup/sources-lookup-credential.route.js b/awx/ui/client/src/inventories-hosts/inventories/related/sources/lookup/sources-lookup-credential.route.js index 90879be5f2..a61e96725e 100644 --- a/awx/ui/client/src/inventories-hosts/inventories/related/sources/lookup/sources-lookup-credential.route.js +++ b/awx/ui/client/src/inventories-hosts/inventories/related/sources/lookup/sources-lookup-credential.route.js @@ -39,7 +39,7 @@ export default { Dataset: ['ListDefinition', 'QuerySet', '$stateParams', 'GetBasePath', '$transition$', (list, qs, $stateParams, GetBasePath, $transition$) => { const toState = $transition$.to(); - toState.params.credential_search.value.kind = _.get($stateParams, 'credential_search.kind', null); + toState.params.credential_search.value.credential_type__namespace = _.get($stateParams, 'credential_search.credential_type__namespace', null); toState.params.credential_search.value.credential_type__kind = _.get($stateParams, 'credential_search.credential_type__kind', null); return qs.search(GetBasePath('credentials'), $stateParams[`${list.iterator}_search`]); }