Skip to content

Commit

Permalink
Add revert certificate functionality to TPv1 (#7784)
Browse files Browse the repository at this point in the history
* Add revert certificate functionality

* Add revert certificate functionality

* Add revert to dropdown

* Update changelog to include changes

* fix pr number
  • Loading branch information
ericholguin committed Sep 6, 2023
1 parent 335406d commit 9e328da
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- [#7646](https://github.com/apache/trafficcontrol/pull/7646) *Traffic Portal* Add the ability to delete a cert.
- [#7652](https://github.com/apache/trafficcontrol/pull/7652) *t3c* added rpmdb checks and use package data from t3c-apply-metadata.json if rpmdb is corrupt.
- [#7674](https://github.com/apache/trafficcontrol/issues/7674) *Traffic Ops* Add the ability to indicate if a server failed its revalidate/config update.
- [#7784](https://github.com/apache/trafficcontrol/pull/7784) *Traffic Portal* Added revert certificate functionality to the ssl-keys page.

### Changed
- [#7757](https://github.com/apache/trafficcontrol/pull/7757) *Traffic Router* Changed Traffic Router to point to api version 5.0 of Traffic Ops.
Expand Down
41 changes: 41 additions & 0 deletions traffic_portal/app/src/common/api/DeliveryServiceSslKeysService.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,47 @@ var DeliveryServiceSslKeysService = function($http, messageModel, ENV) {
}
);
};


this.revertCert = function(deliveryService) {
return $http.get(ENV.api.unstable + "deliveryservices/xmlId/" + deliveryService.xmlId + "/sslkeys", {params: {decode: "true"}}).then(
function(result) {
let prevVersion = parseInt(result.data.response.version, 10) - 1;
$http.get(ENV.api.unstable + "deliveryservices/xmlId/" + deliveryService.xmlId + "/sslkeys", {params: {decode: "true", version: prevVersion}}).then(
function(result) {
let prevKeys = result.data.response;
prevKeys.cdn = deliveryService.cdnName;
prevKeys.deliveryservice = deliveryService.xmlId;

return $http.post(ENV.api.unstable + "deliveryservices/sslkeys/add", prevKeys).then(
function(result) {
messageModel.setMessages(result.data.alerts, false);
return result.data.response;
},
function(err) {
if (err.data && err.data.alerts) {
messageModel.setMessages(err.data.alerts, false);
}
throw err;
}
);
},
function(err) {
if (err.data && err.data.alerts) {
messageModel.setMessages(err.data.alerts, false);
}
throw err;
}
);
},
function(err) {
if (err.data && err.data.alerts) {
messageModel.setMessages(err.data.alerts, false);
}
throw err;
}
);
};
};

DeliveryServiceSslKeysService.$inject = ['$http', 'messageModel', 'ENV'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ var FormDeliveryServiceSslKeysController = function(deliveryService, sslKeys, $s
$state.reload(); // reloads all the resolves for the view
};

$scope.showRevert = function() {
return $scope.sslKeys.version > 1
};

var setSSLKeys = function(sslKeys) {
if (!sslKeys.hostname) {
var url = deliveryService.exampleURLs[0],
Expand Down Expand Up @@ -173,6 +177,31 @@ var FormDeliveryServiceSslKeysController = function(deliveryService, sslKeys, $s
};
init();

$scope.revertCert = function() {
var params = {
title: 'Revert SSL Keys for Delivery Service: ' + deliveryService.xmlId,
message: 'This will replace existing keys with the keys from the previous version'

};
var modalInstance = $uibModal.open({
templateUrl: 'common/modules/dialog/confirm/dialog.confirm.tpl.html',
controller: 'DialogConfirmController',
size: 'md',
resolve: {
params: function () {
return params;
}
}
});
modalInstance.result.then(function() {
deliveryServiceSslKeysService.revertCert(deliveryService).then(
function() {
$anchorScroll();
$scope.refresh();
if ($scope.dsSslKeyForm) $scope.dsSslKeyForm.$setPristine();
});
});
};

};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<ul class="dropdown-menu-right dropdown-menu" uib-dropdown-menu>
<li><a ng-click="generateKeys()">Generate SSL Keys</a></li>
<li><a ng-click="renewCert()">Renew Certificate</a></li>
<li><a ng-click="revertCert()" ng-show="showRevert()">Revert Certificate</a></li>
</ul>
</div>
</div>
Expand Down

0 comments on commit 9e328da

Please sign in to comment.