update inventory source credential lookup queries for api v2

This commit is contained in:
Jake McDermott
2019-06-06 10:16:44 -04:00
committed by Ryan Petrello
parent 6da445f7c0
commit 2f57a1ea93
3 changed files with 59 additions and 37 deletions

View File

@@ -133,25 +133,36 @@ export default ['$state', 'ConfigData', '$scope', 'SourcesFormDefinition', 'Pars
}); });
$scope.lookupCredential = function(){ $scope.lookupCredential = function(){
if($scope.source.value !== "scm" && $scope.source.value !== "custom") { // For most source type selections, we filter for 1-1 matches to credential_type namespace.
let kind = ($scope.source.value === "ec2") ? "aws" : $scope.source.value; let searchKey = 'credential_type__namespace';
$state.go('.credential', { let searchValue = $scope.source.value;
credential_search: {
kind: kind, // SCM and custom source types are more generic in terms of the credentials they
page_size: '5', // accept - any cloud or user-defined credential type can be used. We filter for
page: '1' // 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', { if ($scope.source.value === 'custom') {
credential_search: { searchKey = 'credential_type__kind';
credential_type__kind: "cloud", searchValue = 'cloud';
page_size: '5',
page: '1'
}
});
} }
// 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(){ $scope.lookupProject = function(){
@@ -169,7 +180,7 @@ export default ['$state', 'ConfigData', '$scope', 'SourcesFormDefinition', 'Pars
$scope.credentialBasePath = GetBasePath('credentials') + '?credential_type__kind__in=cloud,network'; $scope.credentialBasePath = GetBasePath('credentials') + '?credential_type__kind__in=cloud,network';
} }
else{ 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") { if (source === 'ec2' || source === 'custom' || source === 'vmware' || source === 'openstack' || source === 'scm' || source === 'cloudforms' || source === "satellite6" || source === "azure_rm") {
$scope.envParseType = 'yaml'; $scope.envParseType = 'yaml';

View File

@@ -302,25 +302,36 @@ export default ['$state', '$scope', 'ParseVariableString', 'ParseTypeChange',
}; };
$scope.lookupCredential = function(){ $scope.lookupCredential = function(){
if($scope.source.value !== "scm" && $scope.source.value !== "custom") { // For most source type selections, we filter for 1-1 matches to credential_type namespace.
let kind = ($scope.source.value === "ec2") ? "aws" : $scope.source.value; let searchKey = 'credential_type__namespace';
$state.go('.credential', { let searchValue = $scope.source.value;
credential_search: {
kind: kind, // SCM and custom source types are more generic in terms of the credentials they
page_size: '5', // accept - any cloud or user-defined credential type can be used. We filter for
page: '1' // 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', { if ($scope.source.value === 'custom') {
credential_search: { searchKey = 'credential_type__kind';
credential_type__kind: "cloud", searchValue = 'cloud';
page_size: '5',
page: '1'
}
});
} }
// 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() { $scope.formCancel = function() {
@@ -384,7 +395,7 @@ export default ['$state', '$scope', 'ParseVariableString', 'ParseTypeChange',
$scope.credentialBasePath = GetBasePath('credentials') + '?credential_type__kind__in=cloud,network'; $scope.credentialBasePath = GetBasePath('credentials') + '?credential_type__kind__in=cloud,network';
} }
else{ 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") { if (source === 'ec2' || source === 'custom' || source === 'vmware' || source === 'openstack' || source === 'scm' || source === 'cloudforms' || source === "satellite6") {
$scope.envParseType = 'yaml'; $scope.envParseType = 'yaml';

View File

@@ -39,7 +39,7 @@ export default {
Dataset: ['ListDefinition', 'QuerySet', '$stateParams', 'GetBasePath', '$transition$', Dataset: ['ListDefinition', 'QuerySet', '$stateParams', 'GetBasePath', '$transition$',
(list, qs, $stateParams, GetBasePath, $transition$) => { (list, qs, $stateParams, GetBasePath, $transition$) => {
const toState = $transition$.to(); 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); 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`]); return qs.search(GetBasePath('credentials'), $stateParams[`${list.iterator}_search`]);
} }