mirror of
https://github.com/ansible/awx.git
synced 2026-01-14 03:10:42 -03:30
Edit schedule credential prompting code cleanup
This commit is contained in:
parent
a5043029c1
commit
ce3dc40649
@ -9,7 +9,7 @@ export default
|
||||
promptData = params.promptData,
|
||||
priorCredentials = params.priorCredentials ? params.priorCredentials : [],
|
||||
newSchedule, rrule, extra_vars;
|
||||
let deferred = $q.defer();
|
||||
const deferred = $q.defer();
|
||||
if (scheduler.isValid()) {
|
||||
Wait('start');
|
||||
newSchedule = scheduler.getValue();
|
||||
@ -68,11 +68,11 @@ export default
|
||||
scheduleData.job_type = promptData.launchConf.defaults.job_type && promptData.launchConf.defaults.job_type === promptData.prompts.jobType.value.value ? null : promptData.prompts.jobType.value.value;
|
||||
}
|
||||
if(_.has(promptData, 'prompts.tags.value') && _.get(promptData, 'launchConf.ask_tags_on_launch')){
|
||||
let templateDefaultJobTags = promptData.launchConf.defaults.job_tags.split(',');
|
||||
const templateDefaultJobTags = promptData.launchConf.defaults.job_tags.split(',');
|
||||
scheduleData.job_tags = (_.isEqual(templateDefaultJobTags.sort(), promptData.prompts.tags.value.map(a => a.value).sort())) ? null : promptData.prompts.tags.value.map(a => a.value).join();
|
||||
}
|
||||
if(_.has(promptData, 'prompts.skipTags.value') && _.get(promptData, 'launchConf.ask_skip_tags_on_launch')){
|
||||
let templateDefaultSkipTags = promptData.launchConf.defaults.skip_tags.split(',');
|
||||
const templateDefaultSkipTags = promptData.launchConf.defaults.skip_tags.split(',');
|
||||
scheduleData.skip_tags = (_.isEqual(templateDefaultSkipTags.sort(), promptData.prompts.skipTags.value.map(a => a.value).sort())) ? null : promptData.prompts.skipTags.value.map(a => a.value).join();
|
||||
}
|
||||
if(_.has(promptData, 'prompts.limit.value') && _.get(promptData, 'launchConf.ask_limit_on_launch')){
|
||||
@ -96,15 +96,15 @@ export default
|
||||
if(_.get(promptData, 'launchConf.ask_credential_on_launch')){
|
||||
// This finds the credentials that were selected in the prompt but don't occur
|
||||
// in the template defaults
|
||||
let credentialsToPost = promptData.prompts.credentials.value.filter(function(credFromPrompt) {
|
||||
let defaultCreds = promptData.launchConf.defaults.credentials ? promptData.launchConf.defaults.credentials : [];
|
||||
const credentialsToPost = promptData.prompts.credentials.value.filter(function(credFromPrompt) {
|
||||
const defaultCreds = promptData.launchConf.defaults.credentials ? promptData.launchConf.defaults.credentials : [];
|
||||
return !defaultCreds.some(function(defaultCred) {
|
||||
return credFromPrompt.id === defaultCred.id;
|
||||
});
|
||||
});
|
||||
|
||||
let promises = [];
|
||||
let schedule = new Schedule();
|
||||
const promises = [];
|
||||
const schedule = new Schedule();
|
||||
|
||||
credentialsToPost.forEach((credentialToPost) => {
|
||||
promises.push(schedule.postCredential({
|
||||
@ -136,27 +136,27 @@ export default
|
||||
Rest.put(scheduleData)
|
||||
.then(({data}) => {
|
||||
if(_.get(promptData, 'launchConf.ask_credential_on_launch')){
|
||||
let credentialsNotInPriorCredentials = promptData.prompts.credentials.value.filter(function(credFromPrompt) {
|
||||
let defaultCreds = promptData.launchConf.defaults.credentials ? promptData.launchConf.defaults.credentials : [];
|
||||
const credentialsNotInPriorCredentials = promptData.prompts.credentials.value.filter(function(credFromPrompt) {
|
||||
const defaultCreds = promptData.launchConf.defaults.credentials ? promptData.launchConf.defaults.credentials : [];
|
||||
return !defaultCreds.some(function(defaultCred) {
|
||||
return credFromPrompt.id === defaultCred.id;
|
||||
});
|
||||
});
|
||||
|
||||
let credentialsToAdd = credentialsNotInPriorCredentials.filter(function(credNotInPrior) {
|
||||
const credentialsToAdd = credentialsNotInPriorCredentials.filter(function(credNotInPrior) {
|
||||
return !priorCredentials.some(function(priorCred) {
|
||||
return credNotInPrior.id === priorCred.id;
|
||||
});
|
||||
});
|
||||
|
||||
let credentialsToRemove = priorCredentials.filter(function(priorCred) {
|
||||
const credentialsToRemove = priorCredentials.filter(function(priorCred) {
|
||||
return !credentialsNotInPriorCredentials.some(function(credNotInPrior) {
|
||||
return priorCred.id === credNotInPrior.id;
|
||||
});
|
||||
});
|
||||
|
||||
let promises = [];
|
||||
let schedule = new Schedule();
|
||||
const promises = [];
|
||||
const schedule = new Schedule();
|
||||
|
||||
credentialsToAdd.forEach((credentialToAdd) => {
|
||||
promises.push(schedule.postCredential({
|
||||
|
||||
@ -286,21 +286,31 @@ function($filter, $state, $stateParams, Wait, $scope, moment,
|
||||
|
||||
let defaultCredsWithoutOverrides = [];
|
||||
|
||||
prompts.credentials.value.forEach((defaultCred) => {
|
||||
let typeMatches = false;
|
||||
const credentialHasScheduleOverride = (templateDefaultCred) => {
|
||||
let credentialHasOverride = false;
|
||||
scheduleCredentials.forEach((scheduleCred) => {
|
||||
if(defaultCred.credential_type === scheduleCred.credential_type) {
|
||||
if((!defaultCred.vault_id && !scheduleCred.inputs.vault_id) || (defaultCred.vault_id && scheduleCred.inputs.vault_id && defaultCred.vault_id === scheduleCred.inputs.vault_id)) {
|
||||
typeMatches = true;
|
||||
if(templateDefaultCred.credential_type === scheduleCred.credential_type) {
|
||||
if(
|
||||
(!templateDefaultCred.vault_id && !scheduleCred.inputs.vault_id) ||
|
||||
(templateDefaultCred.vault_id && scheduleCred.inputs.vault_id && templateDefaultCred.vault_id === scheduleCred.inputs.vault_id)
|
||||
) {
|
||||
credentialHasOverride = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
if(!typeMatches) {
|
||||
defaultCredsWithoutOverrides.push(defaultCred);
|
||||
}
|
||||
});
|
||||
|
||||
prompts.credentials.value = scheduleCredentials.concat(defaultCredsWithoutOverrides);
|
||||
return credentialHasOverride;
|
||||
};
|
||||
|
||||
if(_.has(launchConf, 'defaults.credentials')) {
|
||||
launchConf.defaults.credentials.forEach((defaultCred) => {
|
||||
if(!credentialHasScheduleOverride(defaultCred)) {
|
||||
defaultCredsWithoutOverrides.push(defaultCred);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
prompts.credentials.value = defaultCredsWithoutOverrides.concat(scheduleCredentials);
|
||||
|
||||
if(!launchConf.ask_variables_on_launch) {
|
||||
$scope.noVars = true;
|
||||
|
||||
@ -183,14 +183,13 @@ export default
|
||||
if(!uncheck) {
|
||||
scope.promptData.prompts.credentials.value.push(cred);
|
||||
updateNeededPasswords(cred);
|
||||
for (let i = scope.promptData.credentialTypeMissing.length - 1; i >= 0; i--) {
|
||||
if(scope.promptData.credentialTypeMissing[i].credential_type === cred.credential_type) {
|
||||
if(_.get(cred, 'inputs.vault_id') === _.get(scope.promptData.credentialTypeMissing[i], 'vault_id')) {
|
||||
scope.promptData.credentialTypeMissing.splice(i,1);
|
||||
i = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_.remove(scope.promptData.credentialTypeMissing, (missingCredType) => {
|
||||
return (
|
||||
missingCredType.credential_type === cred.credential_type &&
|
||||
_.get(cred, 'inputs.vault_id') === _.get(missingCredType, 'vault_id')
|
||||
);
|
||||
});
|
||||
} else {
|
||||
if(scope.promptData.launchConf.defaults.credentials && scope.promptData.launchConf.defaults.credentials.length > 0) {
|
||||
checkMissingCredType(cred);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user