mirror of
https://github.com/ansible/awx.git
synced 2026-03-01 00:38:45 -03:30
Merge pull request #7205 from jlmitch5/credentialTypesLookup
Update credential types to lookup values instead of hardcode
This commit is contained in:
@@ -6,8 +6,8 @@
|
|||||||
|
|
||||||
import jobSubmissionController from './job-submission.controller';
|
import jobSubmissionController from './job-submission.controller';
|
||||||
|
|
||||||
export default [ 'templateUrl', 'CreateDialog', 'Wait', 'CreateSelect2', 'ParseTypeChange', 'GetSurveyQuestions', 'i18n',
|
export default [ 'templateUrl', 'CreateDialog', 'Wait', 'CreateSelect2', 'ParseTypeChange', 'GetSurveyQuestions', 'i18n', 'credentialTypesLookup',
|
||||||
function(templateUrl, CreateDialog, Wait, CreateSelect2, ParseTypeChange, GetSurveyQuestions, i18n) {
|
function(templateUrl, CreateDialog, Wait, CreateSelect2, ParseTypeChange, GetSurveyQuestions, i18n, credentialTypesLookup) {
|
||||||
return {
|
return {
|
||||||
scope: {
|
scope: {
|
||||||
submitJobId: '=',
|
submitJobId: '=',
|
||||||
@@ -24,15 +24,18 @@ export default [ 'templateUrl', 'CreateDialog', 'Wait', 'CreateSelect2', 'ParseT
|
|||||||
scope.removeLaunchJobModalReady();
|
scope.removeLaunchJobModalReady();
|
||||||
}
|
}
|
||||||
scope.removeLaunchJobModalReady = scope.$on('LaunchJobModalReady', function() {
|
scope.removeLaunchJobModalReady = scope.$on('LaunchJobModalReady', function() {
|
||||||
|
credentialTypesLookup()
|
||||||
|
.then(kinds => {
|
||||||
|
if(scope.ask_credential_on_launch) {
|
||||||
|
scope.credentialKind = "" + kinds.SSH;
|
||||||
|
scope.includeCredentialList = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Go get the list/survey data that we need from the server
|
// Go get the list/survey data that we need from the server
|
||||||
if(scope.ask_inventory_on_launch) {
|
if(scope.ask_inventory_on_launch) {
|
||||||
scope.includeInventoryList = true;
|
scope.includeInventoryList = true;
|
||||||
}
|
}
|
||||||
if(scope.ask_credential_on_launch) {
|
|
||||||
scope.credentialKind = (scope.ask_credential_on_launch) ? "1" : "5";
|
|
||||||
|
|
||||||
scope.includeCredentialList = true;
|
|
||||||
}
|
|
||||||
if(scope.survey_enabled) {
|
if(scope.survey_enabled) {
|
||||||
GetSurveyQuestions({
|
GetSurveyQuestions({
|
||||||
scope: scope,
|
scope: scope,
|
||||||
|
|||||||
@@ -5,8 +5,9 @@
|
|||||||
*************************************************/
|
*************************************************/
|
||||||
|
|
||||||
export default
|
export default
|
||||||
[ '$scope', 'CredentialList', 'i18n', 'QuerySet', 'GetBasePath',
|
[ '$scope', 'CredentialList', 'i18n', 'QuerySet', 'GetBasePath', 'credentialTypesLookup',
|
||||||
function($scope, CredentialList, i18n, qs, GetBasePath) {
|
function($scope, CredentialList, i18n, qs, GetBasePath, credentialTypesLookup) {
|
||||||
|
let credentialKinds = {};
|
||||||
|
|
||||||
let updateExtraCredentialsList = function() {
|
let updateExtraCredentialsList = function() {
|
||||||
$scope.credentials.forEach((row, i) => {
|
$scope.credentials.forEach((row, i) => {
|
||||||
@@ -69,9 +70,9 @@ export default
|
|||||||
|
|
||||||
$scope.$watchCollection('selectedCredentials.extra', () => {
|
$scope.$watchCollection('selectedCredentials.extra', () => {
|
||||||
if($scope.credentials && $scope.credentials.length > 0) {
|
if($scope.credentials && $scope.credentials.length > 0) {
|
||||||
if($scope.selectedCredentials.extra && $scope.selectedCredentials.extra.length > 0 && parseInt($scope.credentialKind) !== 1) {
|
if($scope.selectedCredentials.extra && $scope.selectedCredentials.extra.length > 0 && parseInt($scope.credentialKind) !== credentialKinds.SSH) {
|
||||||
updateExtraCredentialsList();
|
updateExtraCredentialsList();
|
||||||
} else if (parseInt($scope.credentialKind) !== 1) {
|
} else if (parseInt($scope.credentialKind) !== credentialKinds.SSH) {
|
||||||
uncheckAllCredentials();
|
uncheckAllCredentials();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -79,7 +80,7 @@ export default
|
|||||||
|
|
||||||
$scope.$watch('selectedCredentials.machine', () => {
|
$scope.$watch('selectedCredentials.machine', () => {
|
||||||
if($scope.credentials && $scope.credentials.length > 0) {
|
if($scope.credentials && $scope.credentials.length > 0) {
|
||||||
if($scope.selectedCredentials.machine && parseInt($scope.credentialKind) === 1) {
|
if($scope.selectedCredentials.machine && parseInt($scope.credentialKind) === credentialKinds.SSH) {
|
||||||
updateMachineCredentialList();
|
updateMachineCredentialList();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -90,10 +91,10 @@ export default
|
|||||||
|
|
||||||
$scope.$watchGroup(['credentials', 'selectedCredentials.machine'], () => {
|
$scope.$watchGroup(['credentials', 'selectedCredentials.machine'], () => {
|
||||||
if($scope.credentials && $scope.credentials.length > 0) {
|
if($scope.credentials && $scope.credentials.length > 0) {
|
||||||
if($scope.selectedCredentials.machine && parseInt($scope.credentialKind) === 1) {
|
if($scope.selectedCredentials.machine && parseInt($scope.credentialKind) === credentialKinds.SSH) {
|
||||||
updateMachineCredentialList();
|
updateMachineCredentialList();
|
||||||
}
|
}
|
||||||
else if($scope.selectedCredentials.extra && $scope.selectedCredentials.extra.length > 0 && parseInt($scope.credentialKind) !== 1) {
|
else if($scope.selectedCredentials.extra && $scope.selectedCredentials.extra.length > 0 && parseInt($scope.credentialKind) !== credentialKinds.SSH) {
|
||||||
updateExtraCredentialsList();
|
updateExtraCredentialsList();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -104,7 +105,7 @@ export default
|
|||||||
};
|
};
|
||||||
|
|
||||||
$scope.toggle_row = function(selectedRow) {
|
$scope.toggle_row = function(selectedRow) {
|
||||||
if(parseInt($scope.credentialKind) === 1) {
|
if(parseInt($scope.credentialKind) === credentialKinds.SSH) {
|
||||||
$scope.selectedCredentials.machine = _.cloneDeep(selectedRow);
|
$scope.selectedCredentials.machine = _.cloneDeep(selectedRow);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -117,6 +118,10 @@ export default
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
init();
|
credentialTypesLookup()
|
||||||
|
.then(kinds => {
|
||||||
|
credentialKinds = kinds;
|
||||||
|
init();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|||||||
21
awx/ui/client/src/shared/credentialTypesLookup.factory.js
Normal file
21
awx/ui/client/src/shared/credentialTypesLookup.factory.js
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
export default ['Rest', 'GetBasePath', 'ProcessErrors',
|
||||||
|
function(Rest, GetBasePath, ProcessErrors) {
|
||||||
|
return function() {
|
||||||
|
Rest.setUrl(GetBasePath('credential_types'));
|
||||||
|
return Rest.get()
|
||||||
|
.then(({data}) => {
|
||||||
|
var val = {};
|
||||||
|
data.results.forEach(type => {
|
||||||
|
val[type.name] = type.id;
|
||||||
|
});
|
||||||
|
return val;
|
||||||
|
})
|
||||||
|
.catch(({data, status}) => {
|
||||||
|
ProcessErrors(null, data, status, null, {
|
||||||
|
hdr: 'Error!',
|
||||||
|
msg: 'Failed to GET credential types. Returned status' +
|
||||||
|
status
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}];
|
||||||
@@ -33,6 +33,7 @@ import features from './features/main';
|
|||||||
import orgAdminLookup from './org-admin-lookup/main';
|
import orgAdminLookup from './org-admin-lookup/main';
|
||||||
import limitPanels from './limit-panels/main';
|
import limitPanels from './limit-panels/main';
|
||||||
import multiSelectPreview from './multi-select-preview/main';
|
import multiSelectPreview from './multi-select-preview/main';
|
||||||
|
import credentialTypesLookup from './credentialTypesLookup.factory';
|
||||||
import 'angular-duration-format';
|
import 'angular-duration-format';
|
||||||
|
|
||||||
export default
|
export default
|
||||||
@@ -68,5 +69,6 @@ angular.module('shared', [listGenerator.name,
|
|||||||
])
|
])
|
||||||
.factory('stateDefinitions', stateDefinitions)
|
.factory('stateDefinitions', stateDefinitions)
|
||||||
.factory('lodashAsPromised', lodashAsPromised)
|
.factory('lodashAsPromised', lodashAsPromised)
|
||||||
|
.factory('credentialTypesLookup', credentialTypesLookup)
|
||||||
.directive('truncatedText', truncatedText)
|
.directive('truncatedText', truncatedText)
|
||||||
.provider('$stateExtender', stateExtender);
|
.provider('$stateExtender', stateExtender);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
export default ['templateUrl', 'Rest', 'GetBasePath', 'generateList', '$compile', 'CreateSelect2', 'i18n', 'MultiCredentialService',
|
export default ['templateUrl', 'Rest', 'GetBasePath', 'generateList', '$compile', 'CreateSelect2', 'i18n', 'MultiCredentialService', 'credentialTypesLookup',
|
||||||
function(templateUrl, Rest, GetBasePath, GenerateList, $compile, CreateSelect2, i18n, MultiCredentialService) {
|
function(templateUrl, Rest, GetBasePath, GenerateList, $compile, CreateSelect2, i18n, MultiCredentialService, credentialTypesLookup) {
|
||||||
return {
|
return {
|
||||||
restrict: 'E',
|
restrict: 'E',
|
||||||
scope: {
|
scope: {
|
||||||
@@ -10,43 +10,48 @@ export default ['templateUrl', 'Rest', 'GetBasePath', 'generateList', '$compile'
|
|||||||
templateUrl: templateUrl('templates/job_templates/multi-credential/multi-credential-modal'),
|
templateUrl: templateUrl('templates/job_templates/multi-credential/multi-credential-modal'),
|
||||||
|
|
||||||
link: function(scope, element) {
|
link: function(scope, element) {
|
||||||
scope.credentialKind = "1";
|
credentialTypesLookup()
|
||||||
|
.then(kinds => {
|
||||||
|
scope.credentialKinds = kinds;
|
||||||
|
|
||||||
scope.showModal = function() {
|
scope.credentialKind = "" + kinds.SSH;
|
||||||
$('#multi-credential-modal').modal('show');
|
|
||||||
};
|
|
||||||
|
|
||||||
scope.destroyModal = function() {
|
scope.showModal = function() {
|
||||||
scope.credentialKind = 1;
|
$('#multi-credential-modal').modal('show');
|
||||||
$('#multi-credential-modal').modal('hide');
|
};
|
||||||
};
|
|
||||||
|
|
||||||
scope.generateCredentialList = function() {
|
scope.destroyModal = function() {
|
||||||
let html = GenerateList.build({
|
scope.credentialKind = kinds.SSH;
|
||||||
list: scope.list,
|
$('#multi-credential-modal').modal('hide');
|
||||||
input_type: 'radio',
|
};
|
||||||
mode: 'lookup'
|
|
||||||
});
|
|
||||||
$('#multi-credential-modal-body')
|
|
||||||
.append($compile(html)(scope));
|
|
||||||
};
|
|
||||||
|
|
||||||
$('#multi-credential-modal').on('hidden.bs.modal', function () {
|
scope.generateCredentialList = function() {
|
||||||
$('#multi-credential-modal').off('hidden.bs.modal');
|
let html = GenerateList.build({
|
||||||
$(element).remove();
|
list: scope.list,
|
||||||
});
|
input_type: 'radio',
|
||||||
|
mode: 'lookup'
|
||||||
|
});
|
||||||
|
$('#multi-credential-modal-body')
|
||||||
|
.append($compile(html)(scope));
|
||||||
|
};
|
||||||
|
|
||||||
CreateSelect2({
|
$('#multi-credential-modal').on('hidden.bs.modal', function () {
|
||||||
element: `#multi-credential-kind-select`,
|
$('#multi-credential-modal').off('hidden.bs.modal');
|
||||||
multiple: false,
|
$(element).remove();
|
||||||
placeholder: i18n._('Select a credential')
|
});
|
||||||
});
|
|
||||||
|
|
||||||
MultiCredentialService.getCredentialTypes()
|
CreateSelect2({
|
||||||
.then(({credential_types, credentialTypeOptions}) => {
|
element: `#multi-credential-kind-select`,
|
||||||
scope.credential_types = credential_types;
|
multiple: false,
|
||||||
scope.credentialTypeOptions = credentialTypeOptions;
|
placeholder: i18n._('Select a credential')
|
||||||
scope.$emit('multiCredentialModalLinked');
|
});
|
||||||
|
|
||||||
|
MultiCredentialService.getCredentialTypes()
|
||||||
|
.then(({credential_types, credentialTypeOptions}) => {
|
||||||
|
scope.credential_types = credential_types;
|
||||||
|
scope.credentialTypeOptions = credentialTypeOptions;
|
||||||
|
scope.$emit('multiCredentialModalLinked');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -57,7 +62,7 @@ export default ['templateUrl', 'Rest', 'GetBasePath', 'generateList', '$compile'
|
|||||||
let extraCredIds = $scope.selectedCredentials.extra
|
let extraCredIds = $scope.selectedCredentials.extra
|
||||||
.map(cred => cred.id);
|
.map(cred => cred.id);
|
||||||
$scope.credentials.forEach(cred => {
|
$scope.credentials.forEach(cred => {
|
||||||
if (cred.credential_type !== 1) {
|
if (cred.credential_type !== $scope.credentialKinds.SSH) {
|
||||||
cred.checked = (extraCredIds
|
cred.checked = (extraCredIds
|
||||||
.indexOf(cred.id) > - 1) ? 1 : 0;
|
.indexOf(cred.id) > - 1) ? 1 : 0;
|
||||||
}
|
}
|
||||||
@@ -70,7 +75,7 @@ export default ['templateUrl', 'Rest', 'GetBasePath', 'generateList', '$compile'
|
|||||||
|
|
||||||
let updateMachineCredentialList = function() {
|
let updateMachineCredentialList = function() {
|
||||||
$scope.credentials.forEach(cred => {
|
$scope.credentials.forEach(cred => {
|
||||||
if (cred.credential_type === 1) {
|
if (cred.credential_type === $scope.credentialKinds.SSH) {
|
||||||
cred.checked = ($scope.selectedCredentials
|
cred.checked = ($scope.selectedCredentials
|
||||||
.machine !== null &&
|
.machine !== null &&
|
||||||
cred.id === $scope.selectedCredentials
|
cred.id === $scope.selectedCredentials
|
||||||
@@ -85,7 +90,7 @@ export default ['templateUrl', 'Rest', 'GetBasePath', 'generateList', '$compile'
|
|||||||
|
|
||||||
let updateVaultCredentialList = function() {
|
let updateVaultCredentialList = function() {
|
||||||
$scope.credentials.forEach(cred => {
|
$scope.credentials.forEach(cred => {
|
||||||
if (cred.credential_type === 3) {
|
if (cred.credential_type === $scope.credentialKinds.Vault) {
|
||||||
cred.checked = ($scope.selectedCredentials
|
cred.checked = ($scope.selectedCredentials
|
||||||
.vault !== null &&
|
.vault !== null &&
|
||||||
cred.id === $scope.selectedCredentials
|
cred.id === $scope.selectedCredentials
|
||||||
@@ -153,9 +158,9 @@ export default ['templateUrl', 'Rest', 'GetBasePath', 'generateList', '$compile'
|
|||||||
if($scope.credentials && $scope.credentials.length > 0) {
|
if($scope.credentials && $scope.credentials.length > 0) {
|
||||||
if($scope.selectedCredentials.extra &&
|
if($scope.selectedCredentials.extra &&
|
||||||
$scope.selectedCredentials.extra.length > 0 &&
|
$scope.selectedCredentials.extra.length > 0 &&
|
||||||
parseInt($scope.credentialKind) !== 1) {
|
parseInt($scope.credentialKind) !== $scope.credentialKinds.SSH) {
|
||||||
updateExtraCredentialsList();
|
updateExtraCredentialsList();
|
||||||
} else if (parseInt($scope.credentialKind) !== 1) {
|
} else if (parseInt($scope.credentialKind) !== $scope.credentialKinds.SSH) {
|
||||||
uncheckAllCredentials();
|
uncheckAllCredentials();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -164,7 +169,7 @@ export default ['templateUrl', 'Rest', 'GetBasePath', 'generateList', '$compile'
|
|||||||
$scope.$watch('selectedCredentials.machine', () => {
|
$scope.$watch('selectedCredentials.machine', () => {
|
||||||
if($scope.selectedCredentials &&
|
if($scope.selectedCredentials &&
|
||||||
$scope.selectedCredentials.machine &&
|
$scope.selectedCredentials.machine &&
|
||||||
parseInt($scope.credentialKind) === 1) {
|
parseInt($scope.credentialKind) === $scope.credentialKinds.SSH) {
|
||||||
updateMachineCredentialList();
|
updateMachineCredentialList();
|
||||||
} else {
|
} else {
|
||||||
uncheckAllCredentials();
|
uncheckAllCredentials();
|
||||||
@@ -174,7 +179,7 @@ export default ['templateUrl', 'Rest', 'GetBasePath', 'generateList', '$compile'
|
|||||||
$scope.$watch('selectedCredentials.vault', () => {
|
$scope.$watch('selectedCredentials.vault', () => {
|
||||||
if($scope.selectedCredentials &&
|
if($scope.selectedCredentials &&
|
||||||
$scope.selectedCredentials.vault &&
|
$scope.selectedCredentials.vault &&
|
||||||
parseInt($scope.credentialKind) === 3) {
|
parseInt($scope.credentialKind) === $scope.credentialKinds.Vault) {
|
||||||
updateVaultCredentialList();
|
updateVaultCredentialList();
|
||||||
} else {
|
} else {
|
||||||
uncheckAllCredentials();
|
uncheckAllCredentials();
|
||||||
@@ -188,16 +193,16 @@ export default ['templateUrl', 'Rest', 'GetBasePath', 'generateList', '$compile'
|
|||||||
$scope.credentials.length > 0) {
|
$scope.credentials.length > 0) {
|
||||||
if($scope.selectedCredentials &&
|
if($scope.selectedCredentials &&
|
||||||
$scope.selectedCredentials.machine &&
|
$scope.selectedCredentials.machine &&
|
||||||
parseInt($scope.credentialKind) === 1) {
|
parseInt($scope.credentialKind) === $scope.credentialKinds.SSH) {
|
||||||
updateMachineCredentialList();
|
updateMachineCredentialList();
|
||||||
} else if($scope.selectedCredentials &&
|
} else if($scope.selectedCredentials &&
|
||||||
$scope.selectedCredentials.vault &&
|
$scope.selectedCredentials.vault &&
|
||||||
parseInt($scope.credentialKind) === 3) {
|
parseInt($scope.credentialKind) === $scope.credentialKinds.Vault) {
|
||||||
updateVaultCredentialList();
|
updateVaultCredentialList();
|
||||||
} else if($scope.selectedCredentials &&
|
} else if($scope.selectedCredentials &&
|
||||||
$scope.selectedCredentials.extra &&
|
$scope.selectedCredentials.extra &&
|
||||||
$scope.selectedCredentials.extra.length > 0 &&
|
$scope.selectedCredentials.extra.length > 0 &&
|
||||||
parseInt($scope.credentialKind) !== 1) {
|
parseInt($scope.credentialKind) !== $scope.credentialKinds.SSH) {
|
||||||
updateExtraCredentialsList();
|
updateExtraCredentialsList();
|
||||||
} else {
|
} else {
|
||||||
uncheckAllCredentials();
|
uncheckAllCredentials();
|
||||||
@@ -211,7 +216,7 @@ export default ['templateUrl', 'Rest', 'GetBasePath', 'generateList', '$compile'
|
|||||||
});
|
});
|
||||||
|
|
||||||
$scope.toggle_row = function(selectedRow) {
|
$scope.toggle_row = function(selectedRow) {
|
||||||
if(parseInt($scope.credentialKind) === 1) {
|
if(parseInt($scope.credentialKind) === $scope.credentialKinds.SSH) {
|
||||||
if($scope.selectedCredentials &&
|
if($scope.selectedCredentials &&
|
||||||
$scope.selectedCredentials.machine &&
|
$scope.selectedCredentials.machine &&
|
||||||
$scope.selectedCredentials.machine.id === selectedRow.id) {
|
$scope.selectedCredentials.machine.id === selectedRow.id) {
|
||||||
@@ -219,7 +224,7 @@ export default ['templateUrl', 'Rest', 'GetBasePath', 'generateList', '$compile'
|
|||||||
} else {
|
} else {
|
||||||
$scope.selectedCredentials.machine = _.cloneDeep(selectedRow);
|
$scope.selectedCredentials.machine = _.cloneDeep(selectedRow);
|
||||||
}
|
}
|
||||||
}else if(parseInt($scope.credentialKind) === 3) {
|
}else if(parseInt($scope.credentialKind) === $scope.credentialKinds.Vault) {
|
||||||
if($scope.selectedCredentials &&
|
if($scope.selectedCredentials &&
|
||||||
$scope.selectedCredentials.vault &&
|
$scope.selectedCredentials.vault &&
|
||||||
$scope.selectedCredentials.vault.id === selectedRow.id) {
|
$scope.selectedCredentials.vault.id === selectedRow.id) {
|
||||||
|
|||||||
Reference in New Issue
Block a user