Exemple #1
0
def hosting_post_save_handler(sender, instance, created, using, **kwargs):
    syncano_instance_pk = get_current_instance().pk
    new_cname = Hosting.find_cname(instance.domains)
    if created:
        old_cname = None
    else:
        old_cname = Hosting.find_cname(instance.old_value('domains'))

    if new_cname != old_cname:
        with transaction.atomic():
            syncano_instance = Instance.objects.select_for_update().get(pk=syncano_instance_pk)
            if new_cname is not None:
                add_domains_to_syncano_instance(syncano_instance, domains=[new_cname])
            if old_cname is not None:
                remove_domains_from_syncano_instance(syncano_instance, domains=[old_cname])
            syncano_instance.save(update_fields=['domains'])

    if instance.ssl_status == Hosting.SSL_STATUSES.CHECKING:
        add_post_transaction_success_operation(
            HostingAddSecureCustomDomainTask.delay,
            using=using,
            hosting_pk=instance.id,
            domain=instance.get_cname(),
            instance_pk=syncano_instance_pk,
        )
Exemple #2
0
 def backup_object(self, storage, obj):
     # Remove CNAME and set ssl status to off on backup
     obj['ssl_status'] = Hosting.SSL_STATUSES.OFF
     cname = Hosting.find_cname(obj['domains'])
     if cname:
         obj['domains'].remove(cname)
     super().backup_object(storage, obj)