diff --git a/lemur/common/celery.py b/lemur/common/celery.py index b7f65886..f2a2f826 100644 --- a/lemur/common/celery.py +++ b/lemur/common/celery.py @@ -21,7 +21,10 @@ from lemur.pending_certificates import service as pending_certificate_service from lemur.plugins.base import plugins from lemur.sources.cli import clean, sync, validate_sources -flask_app = create_app() +if current_app: + flask_app = current_app +else: + flask_app = create_app() def make_celery(app): diff --git a/lemur/dns_providers/models.py b/lemur/dns_providers/models.py index d48cd0d1..435a2398 100644 --- a/lemur/dns_providers/models.py +++ b/lemur/dns_providers/models.py @@ -23,7 +23,8 @@ class DnsProvider(db.Model): status = Column(String(length=128), nullable=True) options = Column(JSON, nullable=True) domains = Column(JSON, nullable=True) - certificates = relationship("Certificate", backref='dns_provider', foreign_keys='Certificate.dns_provider_id') + certificates = relationship("Certificate", backref='dns_provider', foreign_keys='Certificate.dns_provider_id', + lazy='dynamic') def __init__(self, name, description, provider_type, credentials): self.name = name diff --git a/lemur/plugins/lemur_acme/plugin.py b/lemur/plugins/lemur_acme/plugin.py index 62e647c4..26ca8ffc 100644 --- a/lemur/plugins/lemur_acme/plugin.py +++ b/lemur/plugins/lemur_acme/plugin.py @@ -333,9 +333,10 @@ class ACMEIssuerPlugin(IssuerPlugin): def __init__(self, *args, **kwargs): super(ACMEIssuerPlugin, self).__init__(*args, **kwargs) - self.acme = AcmeHandler() def get_dns_provider(self, type): + self.acme = AcmeHandler() + provider_types = { 'cloudflare': cloudflare, 'dyn': dyn, @@ -347,12 +348,14 @@ class ACMEIssuerPlugin(IssuerPlugin): return provider def get_all_zones(self, dns_provider): + self.acme = AcmeHandler() dns_provider_options = json.loads(dns_provider.credentials) account_number = dns_provider_options.get("account_id") dns_provider_plugin = self.get_dns_provider(dns_provider.provider_type) return dns_provider_plugin.get_zones(account_number=account_number) def get_ordered_certificate(self, pending_cert): + self.acme = AcmeHandler() acme_client, registration = self.acme.setup_acme_client(pending_cert.authority) order_info = authorization_service.get(pending_cert.external_id) if pending_cert.dns_provider_id: @@ -388,6 +391,7 @@ class ACMEIssuerPlugin(IssuerPlugin): return cert def get_ordered_certificates(self, pending_certs): + self.acme = AcmeHandler() pending = [] certs = [] for pending_cert in pending_certs: @@ -470,6 +474,7 @@ class ACMEIssuerPlugin(IssuerPlugin): :param issuer_options: :return: :raise Exception: """ + self.acme = AcmeHandler() authority = issuer_options.get('authority') create_immediately = issuer_options.get('create_immediately', False) acme_client, registration = self.acme.setup_acme_client(authority)