Create csr modal
The CSR Modal allows users to generate a CSR code. Once the user
types in the necessary information to generate the CSR code, that modal
will then render the code and the user will be able to either copy the
code or download the code in a txt file.
Tested: loaded onto Witherspoon and able to view on certificate
management page. Click on generate csr and type in necessary
(or any additional info), then click on generate CSR. The CSR
code is then visible and is able to be copied or downloaded. In
error state in which CSR code is unable to generate, the modal
closes and an error toast message appears. FYI: Sometimes you
have to reboot system in order for csr to successfully generate.y
Signed-off-by: Mira Murali <miramurali23@gmail.com>
Change-Id: I3cca09c494357496166164b5ee8ff99250ef981d
diff --git a/app/configuration/controllers/certificate-controller.js b/app/configuration/controllers/certificate-controller.js
index 7fa42a1..589035c 100644
--- a/app/configuration/controllers/certificate-controller.js
+++ b/app/configuration/controllers/certificate-controller.js
@@ -10,14 +10,25 @@
'use strict';
angular.module('app.configuration').controller('certificateController', [
- '$scope', 'APIUtils', '$q', 'Constants', 'toastService',
- function($scope, APIUtils, $q, Constants, toastService) {
+ '$scope', 'APIUtils', '$q', 'Constants', 'toastService', '$timeout',
+ function($scope, APIUtils, $q, Constants, toastService, $timeout) {
$scope.loading = false;
$scope.certificates = [];
$scope.availableCertificateTypes = [];
+ $scope.allCertificateTypes = Constants.CERTIFICATE_TYPES;
$scope.addCertificateModal = false;
+ $scope.addCSRModal = false;
$scope.newCertificate = {};
+ $scope.newCSR = {};
$scope.submitted = false;
+ $scope.csrSubmitted = false;
+ $scope.csrCode = '';
+ $scope.displayCSRCode = false;
+ $scope.keyBitLength = Constants.CERTIFICATE.KEY_BIT_LENGTH;
+ $scope.keyPairAlgorithm = Constants.CERTIFICATE.KEY_PAIR_ALGORITHM;
+ $scope.keyCurveId = Constants.CERTIFICATE.KEY_CURVE_ID;
+ $scope.countryList = Constants.COUNTRIES;
+
$scope.loadCertificates = function() {
$scope.certificates = [];
@@ -99,6 +110,96 @@
}
};
+ // add optional name
+ $scope.names = [];
+ $scope.addOptionalRow = function() {
+ $scope.names.push({Value: ''})
+ };
+
+ // remove optional name row
+ $scope.deleteOptionalRow = function(index) {
+ $scope.names.splice(index, 1);
+ if ($scope.names.length == 0) {
+ $scope.names = [];
+ }
+ };
+
+
+ // create a CSR object to send to the backend
+ $scope.getCSRCode = function() {
+ var addCSR = {};
+ let alternativeNames = $scope.names.map(name => name.Value);
+
+ // if user provided a first alternative name then push to alternative
+ // names array
+ $scope.newCSR.firstAlternativeName ?
+ alternativeNames.push($scope.newCSR.firstAlternativeName) :
+ $scope.newCSR.firstAlternativeName = '';
+
+
+ addCSR.CertificateCollection = {
+ '@odata.id': $scope.newCSR.certificateCollection.location
+ };
+ addCSR.CommonName = $scope.newCSR.commonName;
+ addCSR.ContactPerson = $scope.newCSR.contactPerson || '';
+ addCSR.City = $scope.newCSR.city;
+ addCSR.AlternativeNames = alternativeNames || [];
+ addCSR.ChallengePassword = $scope.newCSR.challengePassword || '';
+ addCSR.Email = $scope.newCSR.emailAddress || '';
+ addCSR.Country = $scope.newCSR.countryCode.code;
+ addCSR.Organization = $scope.newCSR.organization;
+ addCSR.OrganizationalUnit = $scope.newCSR.companyUnit;
+ addCSR.KeyCurveId = $scope.newCSR.keyCurveId || '';
+ addCSR.KeyBitLength = $scope.newCSR.keyBitLength
+ addCSR.KeyPairAlgorithm = $scope.newCSR.keyPairAlgorithm || '';
+ addCSR.State = $scope.newCSR.state;
+
+ APIUtils.createCSRCertificate(addCSR).then(
+ function(data) {
+ $scope.displayCSRCode = true;
+ $scope.csrCode = data;
+ },
+ function(error) {
+ $scope.addCSRModal = false;
+ toastService.error('Unable to generate CSR. Try again.');
+ console.log(JSON.stringify(error));
+ })
+ };
+
+ // resetting the modal when user clicks cancel/closes the
+ // modal
+ $scope.resetCSRModal = function() {
+ $scope.addCSRModal = false;
+ $scope.displayCSRCode = false;
+ $scope.newCSR.certificateCollection = $scope.selectOption;
+ $scope.newCSR.commonName = '';
+ $scope.newCSR.contactPerson = '';
+ $scope.newCSR.city = '';
+ $scope.names = [];
+ $scope.newCSR.challengePassword = '';
+ $scope.newCSR.emailAddress = '';
+ $scope.newCSR.countryCode = '';
+ $scope.newCSR.keyCurveId = '';
+ $scope.newCSR.firstAlternativeName = '';
+ $scope.newCSR.keyBitLength = $scope.selectOption;
+ $scope.newCSR.keyPairAlgorithm = $scope.selectOption;
+ $scope.newCSR.organization = '';
+ $scope.newCSR.companyUnit = '';
+ $scope.newCSR.state = '';
+ };
+
+ // copies the CSR code
+ $scope.copySuccess = function(event) {
+ $scope.copied = true;
+ $timeout(function() {
+ $scope.copied = false;
+ }, 5000);
+ };
+ $scope.copyFailed = function(err) {
+ console.log(JSON.stringify(err));
+ };
+
+
var updateAvailableTypes = function(certificate) {
// TODO: at this time only one of each type of certificate is allowed.
// When this changes, this will need to be updated.