Blame SOURCES/pki-core-subsystem-cert-update-CLI-cert-option.patch

632623
From c5312d0b44b5f58ba5b92aba85b89e405213e8a8 Mon Sep 17 00:00:00 2001
632623
From: Dinesh Prasanth M K <dmoluguw@redhat.com>
632623
Date: Fri, 23 Jun 2017 15:57:29 -0400
632623
Subject: [PATCH] Patch for "pki-server subsystem-cert-update" command
632623
632623
Currently, the --cert option has not been implemented for
632623
`pki-server subsystem-cert-update` command. The --cert takes
632623
certificate name that needs to be added to the NSS database
632623
and replaces the existing certificate (if exists) in the
632623
database
632623
632623
https://pagure.io/dogtagpki/issue/2756
632623
632623
Change-Id: If8be9edd55a673230f86e213fc803be365e55a92
632623
(cherry picked from commit d762073c4b5bcd4f9f30e3b8439983a497a77c97)
632623
---
632623
 base/server/python/pki/server/cli/subsystem.py | 29 +++++++++++++++++++++++++-
632623
 1 file changed, 28 insertions(+), 1 deletion(-)
632623
632623
diff --git a/base/server/python/pki/server/cli/subsystem.py b/base/server/python/pki/server/cli/subsystem.py
632623
index 10af8ca..a9857ba 100644
632623
--- a/base/server/python/pki/server/cli/subsystem.py
632623
+++ b/base/server/python/pki/server/cli/subsystem.py
632623
@@ -741,6 +741,7 @@ class SubsystemCertUpdateCLI(pki.cli.CLI):
632623
         print('  -i, --instance <instance ID>    Instance ID (default: pki-tomcat).')
632623
         print('  -v, --verbose                   Run in verbose mode.')
632623
         print('      --help                      Show help message.')
632623
+        print('      --cert <certificate>        New certificate to be added')
632623
         print()
632623
 
632623
     def execute(self, argv):
632623
@@ -748,7 +749,8 @@ class SubsystemCertUpdateCLI(pki.cli.CLI):
632623
         try:
632623
             opts, args = getopt.gnu_getopt(argv, 'i:v', [
632623
                 'instance=',
632623
-                'verbose', 'help'])
632623
+                'verbose', 'help',
632623
+                'cert='])
632623
 
632623
         except getopt.GetoptError as e:
632623
             print('ERROR: ' + str(e))
632623
@@ -756,6 +758,7 @@ class SubsystemCertUpdateCLI(pki.cli.CLI):
632623
             sys.exit(1)
632623
 
632623
         instance_name = 'pki-tomcat'
632623
+        cert_file = None
632623
 
632623
         for o, a in opts:
632623
             if o in ('-i', '--instance'):
632623
@@ -768,6 +771,9 @@ class SubsystemCertUpdateCLI(pki.cli.CLI):
632623
                 self.usage()
632623
                 sys.exit()
632623
 
632623
+            elif o == '--cert':
632623
+                cert_file = a
632623
+
632623
             else:
632623
                 print('ERROR: unknown option ' + o)
632623
                 self.usage()
632623
@@ -807,6 +813,27 @@ class SubsystemCertUpdateCLI(pki.cli.CLI):
632623
 
632623
         token = subsystem_cert['token']
632623
         nssdb = instance.open_nssdb(token)
632623
+
632623
+        if cert_file:
632623
+            if not os.path.isfile(cert_file):
632623
+                print('ERROR: %s certificate does not exist.' % cert_file)
632623
+                self.usage()
632623
+                sys.exit(1)
632623
+
632623
+            data = nssdb.get_cert(
632623
+                nickname=subsystem_cert['nickname'],
632623
+                output_format='base64')
632623
+
632623
+            if data:
632623
+                if self.verbose:
632623
+                    print('Removing old %s certificate from database.' % subsystem_cert['nickname'])
632623
+                nssdb.remove_cert(nickname=subsystem_cert['nickname'])
632623
+            if self.verbose:
632623
+                print('Adding new %s certificate into database.' % subsystem_cert['nickname'])
632623
+            nssdb.add_cert(
632623
+                nickname=subsystem_cert['nickname'],
632623
+                cert_file=cert_file)
632623
+
632623
         data = nssdb.get_cert(
632623
             nickname=subsystem_cert['nickname'],
632623
             output_format='base64')
632623
-- 
632623
1.8.3.1
632623