This is an automated email from the ASF dual-hosted git repository.

shamrick pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git


The following commit(s) were added to refs/heads/master by this push:
     new 9e328dad1c Add revert certificate functionality to TPv1 (#7784)
9e328dad1c is described below

commit 9e328dad1c54cb00e6384b065dd4255db66cb953
Author: Eric Holguin <[email protected]>
AuthorDate: Wed Sep 6 14:46:46 2023 -0600

    Add revert certificate functionality to TPv1 (#7784)
    
    * Add revert certificate functionality
    
    * Add revert certificate functionality
    
    * Add revert to dropdown
    
    * Update changelog to include changes
    
    * fix pr number
---
 CHANGELOG.md                                       |  1 +
 .../common/api/DeliveryServiceSslKeysService.js    | 41 ++++++++++++++++++++++
 .../FormDeliveryServiceSslKeysController.js        | 29 +++++++++++++++
 .../form.deliveryServiceSslKeys.tpl.html           |  1 +
 4 files changed, 72 insertions(+)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index c422fcb923..ba39b32fb9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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.
diff --git a/traffic_portal/app/src/common/api/DeliveryServiceSslKeysService.js 
b/traffic_portal/app/src/common/api/DeliveryServiceSslKeysService.js
index bdec97a1d8..82feb7af72 100644
--- a/traffic_portal/app/src/common/api/DeliveryServiceSslKeysService.js
+++ b/traffic_portal/app/src/common/api/DeliveryServiceSslKeysService.js
@@ -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'];
diff --git 
a/traffic_portal/app/src/common/modules/form/deliveryServiceSslKeys/FormDeliveryServiceSslKeysController.js
 
b/traffic_portal/app/src/common/modules/form/deliveryServiceSslKeys/FormDeliveryServiceSslKeysController.js
index 496ded8b63..4f0c416640 100644
--- 
a/traffic_portal/app/src/common/modules/form/deliveryServiceSslKeys/FormDeliveryServiceSslKeysController.js
+++ 
b/traffic_portal/app/src/common/modules/form/deliveryServiceSslKeys/FormDeliveryServiceSslKeysController.js
@@ -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],
@@ -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();
+                               });
+               });
+       };
 
 };
 
diff --git 
a/traffic_portal/app/src/common/modules/form/deliveryServiceSslKeys/form.deliveryServiceSslKeys.tpl.html
 
b/traffic_portal/app/src/common/modules/form/deliveryServiceSslKeys/form.deliveryServiceSslKeys.tpl.html
index fba753806f..2a57ab02fb 100644
--- 
a/traffic_portal/app/src/common/modules/form/deliveryServiceSslKeys/form.deliveryServiceSslKeys.tpl.html
+++ 
b/traffic_portal/app/src/common/modules/form/deliveryServiceSslKeys/form.deliveryServiceSslKeys.tpl.html
@@ -36,6 +36,7 @@ under the License.
                 <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>

Reply via email to