From 279ad0ad0d8b83ded8ac1a37a087cbeecbef4e9a Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Wed, 28 Jun 2017 15:36:08 +0200 Subject: [PATCH] extract method --- .../mods/dom/DomainProcessorFactory.java | 42 ++++++++++--------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java b/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java index 74972d0..c3294ab 100644 --- a/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java +++ b/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java @@ -51,30 +51,15 @@ public class DomainProcessorFactory implements EntityProcessorFactory { return mainProcessor; } - public Processor createUpdateProcessor(EntityManager em, T entity) throws ProcessorException { + public Processor createUpdateProcessor(final EntityManager em, final T entity) throws ProcessorException { final Domain dom = (Domain) entity; final UnixUser domUser = dom.getUser(); final Pac pac = domUser.getPac(); final Processor apacheVHostSetupProcessor = createApacheVHostSetupProcessor(em, dom); final Processor letencryptSetupProcessor = createACMEBotProcessor(em, dom); - - final String domName = dom.getName(); - final Query query = em.createQuery("SELECT d FROM Domains d WHERE d.domainoptions.name = :option AND d.name = :domname"); - query.setParameter("domname", domName); - query.setParameter("option", "letsencrypt"); - Processor linkLetsencryptCertsProcessor = new NullProcessor(); - if (!query.getResultList().isEmpty()) { - linkLetsencryptCertsProcessor = new ShellProcessor( - "rm -f /etc/apache2/pems-enabled/" + domName + ".crt" + - " && rm -f /etc/apache2/pems-enabled/" + domName + ".key" + - " && rm -f /etc/apache2/pems-enabled/" + domName + ".chain" + - " && ln -s /etc/apache2/pems-generated/" + domName + ".key /etc/apache2/pems-enabled/" + domName + ".key" + - " && ln -s /etc/apache2/pems-generated/" + domName + ".crt /etc/apache2/pems-enabled/" + domName + ".crt" + - " && ln -s /etc/apache2/pems-generated/" + domName + ".chain /etc/apache2/pems-enabled/" + domName + ".chain"); - } - + final Processor triggerAcmebotProcessor = createTriggerAcmebotProcessor(em, dom); final WaitingTasksProcessor processor = new WaitingTasksProcessor( - new CompoundProcessor(apacheVHostSetupProcessor, letencryptSetupProcessor, linkLetsencryptCertsProcessor)); + new CompoundProcessor(apacheVHostSetupProcessor, letencryptSetupProcessor, triggerAcmebotProcessor)); final Config config = Config.getInstance(); for (String queueName : config.getProperty("queues.mail").split(",")) { processor.appendProcessor(queueName, createMailinSetupProcessor(em, dom, pac), queueName + ".hostsharing.net"); @@ -82,7 +67,7 @@ public class DomainProcessorFactory implements EntityProcessorFactory { return processor; } - public Processor createDeleteProcessor(EntityManager em, T entity) throws ProcessorException { + public Processor createDeleteProcessor(final EntityManager em, final T entity) throws ProcessorException { final Domain dom = (Domain) entity; final String domName = dom.getName(); final WaitingTasksProcessor mainProcessor = new WaitingTasksProcessor( @@ -344,6 +329,25 @@ public class DomainProcessorFactory implements EntityProcessorFactory { return vhostDelProcessor; } + private Processor createTriggerAcmebotProcessor(final EntityManager em, final Domain dom) { + final String domName = dom.getName(); + final Query query = em.createQuery("SELECT d FROM Domains d WHERE d.domainoptions.name = :option AND d.name = :domname"); + query.setParameter("domname", domName); + query.setParameter("option", "letsencrypt"); + if (query.getResultList().isEmpty()) { + return new NullProcessor(); + } else { + return new ShellProcessor( + "rm -f /etc/apache2/pems-enabled/" + domName + ".crt" + + " && rm -f /etc/apache2/pems-enabled/" + domName + ".key" + + " && rm -f /etc/apache2/pems-enabled/" + domName + ".chain" + + " && ln -s /etc/apache2/pems-generated/" + domName + ".key /etc/apache2/pems-enabled/" + domName + ".key" + + " && ln -s /etc/apache2/pems-generated/" + domName + ".crt /etc/apache2/pems-enabled/" + domName + ".crt" + + " && ln -s /etc/apache2/pems-generated/" + domName + ".chain /etc/apache2/pems-enabled/" + domName + ".chain" + + " && sudo -u acmebot /usr/sbin/acmebot -d " + domName); + } + } + private Processor createACMEBotProcessor(final EntityManager em, final Domain dom) throws ProcessorException { final Query query = em.createQuery("SELECT d FROM Domains d WHERE d.domainoptions.name = :option AND d.user.pac.hive.name = :hivename"); final String hiveName = dom.getHiveName();