To improve reusability the PKIDeployer class has been moved from the pkihelper.py into the top level pki.server.deployment module.
-- Endi S. Dewata
>From 202365ea7ff3cd85e16243b751f9f56bb8018ed6 Mon Sep 17 00:00:00 2001 From: "Endi S. Dewata" <[email protected]> Date: Wed, 21 Dec 2016 16:12:19 +0100 Subject: [PATCH] Refactored PKIDeployer. To improve reusability the PKIDeployer class has been moved from the pkihelper.py into the top level pki.server.deployment module. --- .../python/pki/server/deployment/__init__.py | 128 +++++++++++++++++++++ .../python/pki/server/deployment/pkihelper.py | 101 ---------------- .../server/deployment/scriptlets/configuration.py | 3 +- base/server/sbin/pkidestroy | 4 +- base/server/sbin/pkispawn | 4 +- 5 files changed, 133 insertions(+), 107 deletions(-) diff --git a/base/server/python/pki/server/deployment/__init__.py b/base/server/python/pki/server/deployment/__init__.py index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..641c05d39f235d21a1db592013b7e5d8b9ed27e0 100644 --- a/base/server/python/pki/server/deployment/__init__.py +++ b/base/server/python/pki/server/deployment/__init__.py @@ -0,0 +1,128 @@ +# Authors: +# Matthew Harmsen <[email protected]> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Copyright (C) 2016 Red Hat, Inc. +# All rights reserved. +# + +from __future__ import absolute_import +import os +from lxml import etree + +from . import pkiconfig as config +from . import pkihelper as util + + +class PKIDeployer: + """Holds the global dictionaries and the utility objects""" + + def __init__(self): + + # PKI Deployment "Mandatory" Command-Line Variables + self.subsystem_name = None + + # Global dictionary variables + self.mdict = {} + self.slots = {} + self.main_config = None + self.user_config = None + self.manifest_db = [] + + self.identity = None + self.namespace = None + self.configuration_file = None + self.instance = None + self.directory = None + self.file = None + self.symlink = None + self.war = None + self.password = None + self.hsm = None + self.certutil = None + self.modutil = None + self.pk12util = None + self.kra_connector = None + self.security_domain = None + self.servercertnick_conf = None + self.systemd = None + self.tps_connector = None + self.config_client = None + + def init(self): + + # Utility objects + self.identity = util.Identity(self) + self.namespace = util.Namespace(self) + self.configuration_file = util.ConfigurationFile(self) + self.instance = util.Instance(self) + self.directory = util.Directory(self) + self.file = util.File(self) + self.symlink = util.Symlink(self) + self.war = util.War(self) + self.password = util.Password(self) + self.hsm = util.HSM(self) + self.certutil = util.Certutil(self) + self.modutil = util.Modutil(self) + self.pk12util = util.PK12util(self) + self.kra_connector = util.KRAConnector(self) + self.security_domain = util.SecurityDomain(self) + self.servercertnick_conf = util.ServerCertNickConf(self) + self.systemd = util.Systemd(self) + self.tps_connector = util.TPSConnector(self) + self.config_client = util.ConfigClient(self) + + def deploy_webapp(self, name, doc_base, descriptor): + """ + Deploy a web application into a Tomcat instance. + + This method will copy the specified deployment descriptor into + <instance>/conf/Catalina/localhost/<name>.xml and point the docBase + to the specified location. The web application will become available + under "/<name>" URL path. + + See also: http://tomcat.apache.org/tomcat-7.0-doc/config/context.html + + :param name: Web application name. + :type name: str + :param doc_base: Path to web application content. + :type doc_base: str + :param descriptor: Path to deployment descriptor (context.xml). + :type descriptor: str + """ + new_descriptor = os.path.join( + self.mdict['pki_instance_configuration_path'], + "Catalina", + "localhost", + name + ".xml") + + parser = etree.XMLParser(remove_blank_text=True) + document = etree.parse(descriptor, parser) + + context = document.getroot() + context.set('docBase', doc_base) + + with open(new_descriptor, 'wb') as f: + # xml as UTF-8 encoded bytes + document.write(f, pretty_print=True, encoding='utf-8') + + os.chown(new_descriptor, self.mdict['pki_uid'], self.mdict['pki_gid']) + os.chmod( + new_descriptor, + config.PKI_DEPLOYMENT_DEFAULT_FILE_PERMISSIONS) + + @staticmethod + def create_system_cert_verifier(instance=None, subsystem=None): + return util.SystemCertificateVerifier(instance, subsystem) diff --git a/base/server/python/pki/server/deployment/pkihelper.py b/base/server/python/pki/server/deployment/pkihelper.py index 75d0fb20b8f24f9820926ce5af637665d0e29800..c9fe50d96ce9c9cb3c1acfd39ee4af917a76c32a 100644 --- a/base/server/python/pki/server/deployment/pkihelper.py +++ b/base/server/python/pki/server/deployment/pkihelper.py @@ -36,7 +36,6 @@ from grp import getgrnam from pwd import getpwnam from pwd import getpwuid import xml.etree.ElementTree as ET -from lxml import etree import zipfile # PKI Deployment Imports @@ -4579,103 +4578,3 @@ class SystemCertificateVerifier: e.output, extra=config.PKI_INDENTATION_LEVEL_2) raise - - -class PKIDeployer: - """Holds the global dictionaries and the utility objects""" - - def __init__(self): - # PKI Deployment "Mandatory" Command-Line Variables - self.subsystem_name = None - - # Global dictionary variables - self.mdict = {} - self.slots = {} - self.main_config = None - self.user_config = None - self.manifest_db = [] - - self.identity = None - self.namespace = None - self.configuration_file = None - self.instance = None - self.directory = None - self.file = None - self.symlink = None - self.war = None - self.password = None - self.hsm = None - self.certutil = None - self.modutil = None - self.pk12util = None - self.kra_connector = None - self.security_domain = None - self.servercertnick_conf = None - self.systemd = None - self.tps_connector = None - self.config_client = None - - def init(self): - # Utility objects - self.identity = Identity(self) - self.namespace = Namespace(self) - self.configuration_file = ConfigurationFile(self) - self.instance = Instance(self) - self.directory = Directory(self) - self.file = File(self) - self.symlink = Symlink(self) - self.war = War(self) - self.password = Password(self) - self.hsm = HSM(self) - self.certutil = Certutil(self) - self.modutil = Modutil(self) - self.pk12util = PK12util(self) - self.kra_connector = KRAConnector(self) - self.security_domain = SecurityDomain(self) - self.servercertnick_conf = ServerCertNickConf(self) - self.systemd = Systemd(self) - self.tps_connector = TPSConnector(self) - self.config_client = ConfigClient(self) - - def deploy_webapp(self, name, doc_base, descriptor): - """ - Deploy a web application into a Tomcat instance. - - This method will copy the specified deployment descriptor into - <instance>/conf/Catalina/localhost/<name>.xml and point the docBase - to the specified location. The web application will become available - under "/<name>" URL path. - - See also: http://tomcat.apache.org/tomcat-7.0-doc/config/context.html - - :param name: Web application name. - :type name: str - :param doc_base: Path to web application content. - :type doc_base: str - :param descriptor: Path to deployment descriptor (context.xml). - :type descriptor: str - """ - new_descriptor = os.path.join( - self.mdict['pki_instance_configuration_path'], - "Catalina", - "localhost", - name + ".xml") - - parser = etree.XMLParser(remove_blank_text=True) - document = etree.parse(descriptor, parser) - - context = document.getroot() - context.set('docBase', doc_base) - - with open(new_descriptor, 'wb') as f: - # xml as UTF-8 encoded bytes - document.write(f, pretty_print=True, encoding='utf-8') - - os.chown(new_descriptor, self.mdict['pki_uid'], self.mdict['pki_gid']) - os.chmod( - new_descriptor, - config.PKI_DEPLOYMENT_DEFAULT_FILE_PERMISSIONS) - - @staticmethod - def create_system_cert_verifier(instance=None, subsystem=None): - return SystemCertificateVerifier(instance, subsystem) diff --git a/base/server/python/pki/server/deployment/scriptlets/configuration.py b/base/server/python/pki/server/deployment/scriptlets/configuration.py index 64ee4e5f6f5cbc920c7ac5a27ab995d7155cf1cc..c9166f1ee7b587778e4f74edf0bca1afbfab4f31 100644 --- a/base/server/python/pki/server/deployment/scriptlets/configuration.py +++ b/base/server/python/pki/server/deployment/scriptlets/configuration.py @@ -25,7 +25,6 @@ import re # PKI Deployment Imports from .. import pkiconfig as config -from .. import pkihelper from .. import pkimessages as log from .. import pkiscriptlet @@ -278,7 +277,7 @@ class PkiScriptlet(pkiscriptlet.AbstractBasePkiScriptlet): # raises exception on failure config.pki_log.info("validating the signing certificate", extra=config.PKI_INDENTATION_LEVEL_2) - verifier = pkihelper.PKIDeployer.create_system_cert_verifier( + verifier = pki.server.deployment.PKIDeployer.create_system_cert_verifier( instance, 'ca') verifier.verify_certificate('signing') diff --git a/base/server/sbin/pkidestroy b/base/server/sbin/pkidestroy index 46c47fc368a17a4343690f7e78fb5ff28f3acb2c..ca16bb2e756eb5966e87d0c04bfb398c35a71e21 100755 --- a/base/server/sbin/pkidestroy +++ b/base/server/sbin/pkidestroy @@ -37,11 +37,11 @@ try: import time import traceback from time import strftime as date + import pki from pki.server.deployment import pkiconfig as config from pki.server.deployment.pkiparser import PKIConfigParser from pki.server.deployment import pkilogging from pki.server.deployment import pkimessages as log - import pki.server.deployment.pkihelper as util except ImportError: print("""\ There was a problem importing one of the required Python modules. The @@ -52,7 +52,7 @@ error was: sys.exit(1) -deployer = util.PKIDeployer() +deployer = pki.server.deployment.PKIDeployer() # Handle the Keyboard Interrupt diff --git a/base/server/sbin/pkispawn b/base/server/sbin/pkispawn index 8726eb77e440bc4d7f76290b54708031392b4925..1ffa435ab381a0d7397341347d711142cec2316e 100755 --- a/base/server/sbin/pkispawn +++ b/base/server/sbin/pkispawn @@ -39,12 +39,12 @@ try: import time import traceback from time import strftime as date + import pki from pki.server.deployment import pkiconfig as config from pki.server.deployment import pkimanifest as manifest from pki.server.deployment.pkiparser import PKIConfigParser from pki.server.deployment import pkilogging from pki.server.deployment import pkimessages as log - import pki.server.deployment.pkihelper as util except ImportError: print("""\ There was a problem importing one of the required Python modules. The @@ -55,7 +55,7 @@ error was: sys.exit(1) -deployer = util.PKIDeployer() +deployer = pki.server.deployment.PKIDeployer() # Handle the Keyboard Interrupt -- 2.5.5
_______________________________________________ Pki-devel mailing list [email protected] https://www.redhat.com/mailman/listinfo/pki-devel
