added password prompting for adhoc commands

This commit is contained in:
John Mitchell
2015-04-08 16:17:05 -04:00
parent 9500e9b63e
commit 20dc2c1c7d

View File

@@ -12,9 +12,9 @@
* @description This controller controls the adhoc form creation, command launching and navigating to standard out after command has been succesfully ran. * @description This controller controls the adhoc form creation, command launching and navigating to standard out after command has been succesfully ran.
*/ */
export function AdhocCtrl($scope, $rootScope, $location, $routeParams, export function AdhocCtrl($scope, $rootScope, $location, $routeParams,
AdhocForm, GenerateForm, Rest, ProcessErrors, ClearScope, GetBasePath, CheckPasswords, PromptForPasswords, CreateLaunchDialog, AdhocForm, GenerateForm, Rest, ProcessErrors, ClearScope,
GetChoices, KindChange, LookUpInit, CredentialList, Empty, OwnerChange, GetBasePath, GetChoices, KindChange, LookUpInit, CredentialList, Empty,
LoginMethodChange, Wait) { Wait) {
ClearScope(); ClearScope();
@@ -76,9 +76,6 @@ export function AdhocCtrl($scope, $rootScope, $location, $routeParams,
input_type: 'radio' input_type: 'radio'
}); });
OwnerChange({ scope: $scope });
LoginMethodChange({ scope: $scope });
Wait('stop'); // END: form population Wait('stop'); // END: form population
}); });
@@ -91,24 +88,12 @@ export function AdhocCtrl($scope, $rootScope, $location, $routeParams,
callback: 'choicesReadyAdhoc' callback: 'choicesReadyAdhoc'
}); });
// Handle Owner change
$scope.ownerChange = function () {
OwnerChange({ scope: $scope });
};
// Handle Login Method change
$scope.loginMethodChange = function () {
LoginMethodChange({ scope: $scope });
};
// Handle Kind change
$scope.kindChange = function () {
KindChange({ scope: $scope, form: form, reset: true });
};
// launch the job with the provided form data // launch the job with the provided form data
$scope.launchJob = function () { $scope.launchJob = function () {
var fld, data={}; var fld, data={}, html;
html = '<form class="ng-valid ng-valid-required" name="job_launch_form"' +
'id="job_launch_form" autocomplete="off" nonvalidate>';
// stub the payload with defaults from DRF // stub the payload with defaults from DRF
data = { data = {
@@ -135,22 +120,92 @@ export function AdhocCtrl($scope, $rootScope, $location, $routeParams,
Wait('start'); Wait('start');
// Launch the adhoc job if ($scope.removeStartAdhocRun) {
Rest.setUrl(url); $scope.removeStartAdhocRun();
Rest.post(data) }
.success(function (data) { $scope.removeStartAdhocRun = $scope.$on('StartAdhocRun', function() {
Wait('stop'); var password;
$location.path("/ad_hoc_commands/" + data.id); for (password in $scope.passwords) {
}) data[$scope.passwords[password]] = $scope[$scope.passwords[password]];
.error(function (data, status) { }
ProcessErrors($scope, data, status, form, { hdr: 'Error!', // Launch the adhoc job
msg: 'Failed to launch adhoc command. POST returned status: ' + Rest.setUrl(GetBasePath('inventory') +
status }); $routeParams.inventory_id + '/ad_hoc_commands/');
// TODO: still need to implement popping up a password prompt Rest.post(data)
// if the credential requires it. The way that the current end- .success(function (data) {
// point works is that I find out if I need to ask for a Wait('stop');
// password from POST, thus I get an error response. $location.path("/ad_hoc_commands/" + data.id);
})
.error(function (data, status) {
ProcessErrors($scope, data, status, form, { hdr: 'Error!',
msg: 'Failed to launch adhoc command. POST returned ' +
'status: ' + status });
});
});
if ($scope.removeCreateLaunchDialog) {
$scope.removeCreateLaunchDialog();
}
$scope.removeCreateLaunchDialog = $scope.$on('CreateLaunchDialog',
function(e, html, url) {
CreateLaunchDialog({
scope: $scope,
html: html,
url: url,
callback: 'StartAdhocRun'
});
}); });
if ($scope.removePromptForPasswords) {
$scope.removePromptForPasswords();
}
$scope.removePromptForPasswords = $scope.$on('PromptForPasswords', function(e, passwords_needed_to_start,html, url) {
PromptForPasswords({ scope: $scope,
passwords: passwords_needed_to_start,
callback: 'CreateLaunchDialog',
html: html,
url: url
});
});
if ($scope.removeContinueCred) {
$scope.removeContinueCred();
}
$scope.removeContinueCred = $scope.$on('ContinueCred', function(e, passwords) {
if(passwords.length>0){
$scope.passwords_needed_to_start = passwords;
// only go through the password prompting steps if there are
// passwords to prompt for
$scope.$emit('PromptForPasswords', passwords, html, url);
} else {
// if not, go straight to trying to run the job.
$scope.$emit('StartAdhocRun', url);
}
});
// start adhoc launching routine
CheckPasswords({
scope: $scope,
credential: $scope.credential,
callback: 'ContinueCred'
});
// // Launch the adhoc job
// Rest.setUrl(url);
// Rest.post(data)
// .success(function (data) {
// Wait('stop');
// $location.path("/ad_hoc_commands/" + data.id);
// })
// .error(function (data, status) {
// ProcessErrors($scope, data, status, form, { hdr: 'Error!',
// msg: 'Failed to launch adhoc command. POST returned status: ' +
// status });
// // TODO: still need to implement popping up a password prompt
// // if the credential requires it. The way that the current end-
// // point works is that I find out if I need to ask for a
// // password from POST, thus I get an error response.
// });
}; };
// Remove all data input into the form // Remove all data input into the form
@@ -161,12 +216,10 @@ export function AdhocCtrl($scope, $rootScope, $location, $routeParams,
} }
$scope.limit = $scope.providedHostPatterns; $scope.limit = $scope.providedHostPatterns;
KindChange({ scope: $scope, form: form, reset: false }); KindChange({ scope: $scope, form: form, reset: false });
OwnerChange({ scope: $scope });
LoginMethodChange({ scope: $scope });
}; };
} }
AdhocCtrl.$inject = ['$scope', '$rootScope', '$location', '$routeParams', AdhocCtrl.$inject = ['$scope', '$rootScope', '$location', '$routeParams',
'AdhocForm', 'GenerateForm', 'Rest', 'ProcessErrors', 'ClearScope', 'CheckPasswords', 'PromptForPasswords', 'CreateLaunchDialog', 'AdhocForm',
'GetBasePath', 'GetChoices', 'KindChange', 'LookUpInit', 'CredentialList', 'GenerateForm', 'Rest', 'ProcessErrors', 'ClearScope', 'GetBasePath',
'Empty', 'OwnerChange', 'LoginMethodChange', 'Wait']; 'GetChoices', 'KindChange', 'LookUpInit', 'CredentialList', 'Empty', 'Wait'];