extract method
This commit is contained in:
parent
4934c2d085
commit
279ad0ad0d
@ -51,30 +51,15 @@ public class DomainProcessorFactory implements EntityProcessorFactory {
|
|||||||
return mainProcessor;
|
return mainProcessor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends AbstractEntity> Processor createUpdateProcessor(EntityManager em, T entity) throws ProcessorException {
|
public <T extends AbstractEntity> Processor createUpdateProcessor(final EntityManager em, final T entity) throws ProcessorException {
|
||||||
final Domain dom = (Domain) entity;
|
final Domain dom = (Domain) entity;
|
||||||
final UnixUser domUser = dom.getUser();
|
final UnixUser domUser = dom.getUser();
|
||||||
final Pac pac = domUser.getPac();
|
final Pac pac = domUser.getPac();
|
||||||
final Processor apacheVHostSetupProcessor = createApacheVHostSetupProcessor(em, dom);
|
final Processor apacheVHostSetupProcessor = createApacheVHostSetupProcessor(em, dom);
|
||||||
final Processor letencryptSetupProcessor = createACMEBotProcessor(em, dom);
|
final Processor letencryptSetupProcessor = createACMEBotProcessor(em, dom);
|
||||||
|
final Processor triggerAcmebotProcessor = createTriggerAcmebotProcessor(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 WaitingTasksProcessor processor = new WaitingTasksProcessor(
|
final WaitingTasksProcessor processor = new WaitingTasksProcessor(
|
||||||
new CompoundProcessor(apacheVHostSetupProcessor, letencryptSetupProcessor, linkLetsencryptCertsProcessor));
|
new CompoundProcessor(apacheVHostSetupProcessor, letencryptSetupProcessor, triggerAcmebotProcessor));
|
||||||
final Config config = Config.getInstance();
|
final Config config = Config.getInstance();
|
||||||
for (String queueName : config.getProperty("queues.mail").split(",")) {
|
for (String queueName : config.getProperty("queues.mail").split(",")) {
|
||||||
processor.appendProcessor(queueName, createMailinSetupProcessor(em, dom, pac), queueName + ".hostsharing.net");
|
processor.appendProcessor(queueName, createMailinSetupProcessor(em, dom, pac), queueName + ".hostsharing.net");
|
||||||
@ -82,7 +67,7 @@ public class DomainProcessorFactory implements EntityProcessorFactory {
|
|||||||
return processor;
|
return processor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends AbstractEntity> Processor createDeleteProcessor(EntityManager em, T entity) throws ProcessorException {
|
public <T extends AbstractEntity> Processor createDeleteProcessor(final EntityManager em, final T entity) throws ProcessorException {
|
||||||
final Domain dom = (Domain) entity;
|
final Domain dom = (Domain) entity;
|
||||||
final String domName = dom.getName();
|
final String domName = dom.getName();
|
||||||
final WaitingTasksProcessor mainProcessor = new WaitingTasksProcessor(
|
final WaitingTasksProcessor mainProcessor = new WaitingTasksProcessor(
|
||||||
@ -344,6 +329,25 @@ public class DomainProcessorFactory implements EntityProcessorFactory {
|
|||||||
return vhostDelProcessor;
|
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 {
|
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 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();
|
final String hiveName = dom.getHiveName();
|
||||||
|
Loading…
Reference in New Issue
Block a user