Example #1
0
    def test_enable_insecure_serializers(self):
        with patch('kombu.serialization.registry') as registry:
            enable_insecure_serializers()
            registry.assert_has_calls([
                call.enable('pickle'), call.enable('yaml'),
                call.enable('msgpack'),
            ])
            registry.enable.side_effect = KeyError()
            enable_insecure_serializers()

        with patch('kombu.serialization.registry') as registry:
            enable_insecure_serializers(['msgpack'])
            registry.assert_has_calls([call.enable('msgpack')])
Example #2
0
    def test_enable_insecure_serializers(self):
        with patch('kombu.serialization.registry') as registry:
            enable_insecure_serializers()
            registry.assert_has_calls([
                call.enable('pickle'), call.enable('yaml'),
                call.enable('msgpack'),
            ])
            registry.enable.side_effect = KeyError()
            enable_insecure_serializers()

        with patch('kombu.serialization.registry') as registry:
            enable_insecure_serializers(['msgpack'])
            registry.assert_has_calls([call.enable('msgpack')])
Example #3
0
    def __init__(self, main=None, loader=None, backend=None,
                 amqp=None, events=None, log=None, control=None,
                 set_as_current=True, accept_magic_kwargs=False,
                 tasks=None, broker=None, include=None, changes=None,
                 config_source=None, fixups=None, **kwargs):
        self.clock = LamportClock()
        self.main = main
        self.amqp_cls = amqp or self.amqp_cls
        self.backend_cls = backend or self.backend_cls
        self.events_cls = events or self.events_cls
        self.loader_cls = loader or self.loader_cls
        self.log_cls = log or self.log_cls
        self.control_cls = control or self.control_cls
        self.set_as_current = set_as_current
        self.registry_cls = symbol_by_name(self.registry_cls)
        self.accept_magic_kwargs = accept_magic_kwargs
        self.user_options = defaultdict(set)
        self._config_source = config_source
        self.steps = defaultdict(set)

        self.configured = False
        self._pending_defaults = deque()

        self.finalized = False
        self._finalize_mutex = threading.Lock()
        self._pending = deque()
        self._tasks = tasks
        if not isinstance(self._tasks, TaskRegistry):
            self._tasks = TaskRegistry(self._tasks or {})

        # If the class defins a custom __reduce_args__ we need to use
        # the old way of pickling apps, which is pickling a list of
        # args instead of the new way that pickles a dict of keywords.
        self._using_v1_reduce = app_has_custom(self, '__reduce_args__')

        # these options are moved to the config to
        # simplify pickling of the app object.
        self._preconf = changes or {}
        if broker:
            self._preconf['BROKER_URL'] = broker
        if include:
            self._preconf['CELERY_IMPORTS'] = include

        enable_insecure_serializers()

        # Apply fixups.
        self.fixups = set(fixups or ())
        for fixup in self.fixups | BUILTIN_FIXUPS:
            symbol_by_name(fixup)(self)

        if self.set_as_current:
            self.set_current()

        # See Issue #1126
        # this is used when pickling the app object so that configuration
        # is reread without having to pickle the contents
        # (which is often unpickleable anyway)
        if self._config_source:
            self.config_from_object(self._config_source)

        self.on_init()
        _register_app(self)
Example #4
0
    def __init__(self,
                 main=None,
                 loader=None,
                 backend=None,
                 amqp=None,
                 events=None,
                 log=None,
                 control=None,
                 set_as_current=True,
                 accept_magic_kwargs=False,
                 tasks=None,
                 broker=None,
                 include=None,
                 changes=None,
                 config_source=None,
                 fixups=None,
                 **kwargs):
        self.clock = LamportClock()
        self.main = main
        self.amqp_cls = amqp or self.amqp_cls
        self.backend_cls = backend or self.backend_cls
        self.events_cls = events or self.events_cls
        self.loader_cls = loader or self.loader_cls
        self.log_cls = log or self.log_cls
        self.control_cls = control or self.control_cls
        self.set_as_current = set_as_current
        self.registry_cls = symbol_by_name(self.registry_cls)
        self.accept_magic_kwargs = accept_magic_kwargs
        self.user_options = defaultdict(set)
        self._config_source = config_source
        self.steps = defaultdict(set)

        self.configured = False
        self._pending_defaults = deque()

        self.finalized = False
        self._finalize_mutex = threading.Lock()
        self._pending = deque()
        self._tasks = tasks
        if not isinstance(self._tasks, TaskRegistry):
            self._tasks = TaskRegistry(self._tasks or {})

        # If the class defins a custom __reduce_args__ we need to use
        # the old way of pickling apps, which is pickling a list of
        # args instead of the new way that pickles a dict of keywords.
        self._using_v1_reduce = app_has_custom(self, '__reduce_args__')

        # these options are moved to the config to
        # simplify pickling of the app object.
        self._preconf = changes or {}
        if broker:
            self._preconf['BROKER_URL'] = broker
        if include:
            self._preconf['CELERY_IMPORTS'] = include

        enable_insecure_serializers()

        # Apply fixups.
        self.fixups = set(fixups or ())
        for fixup in self.fixups | BUILTIN_FIXUPS:
            symbol_by_name(fixup)(self)

        if self.set_as_current:
            self.set_current()

        # See Issue #1126
        # this is used when pickling the app object so that configuration
        # is reread without having to pickle the contents
        # (which is often unpickleable anyway)
        if self._config_source:
            self.config_from_object(self._config_source)

        self.on_init()
        _register_app(self)
Example #5
0
import os
from io import BytesIO
from datetime import datetime
import urllib.request
from urllib.parse import urlparse
import requests
import celery
from kombu import serialization
import celeryconfig
import service.resources.bluebeam as bluebeam
from service.resources.models import SubmissionModel, ExportStatusModel
from service.resources.db import create_session

TEMP_DIR = 'tmp'
serialization.register_pickle()
serialization.enable_insecure_serializers()

# pylint: disable=invalid-name
celery_app = celery.Celery('bluebeam-microservice')
celery_app.config_from_object(celeryconfig)
# pylint: enable=invalid-name

SPREADSHEETS_URL = os.environ.get('SPREADSHEETS_MICROSERVICE_URL').rstrip('/')
SPREADSHEETS_API_KEY = os.environ.get('SPREADSHEETS_MICROSERVICE_API_KEY')

ERR_UPLOAD_FAIL = "Unable to upload file"
ERR_INVALID_PROJECT_ID = "Invalid Bluebeam project id"
STATUS_FILES_UPLOADED = "Files uploaded"


@celery_app.task(name="tasks.bluebeam_export", bind=True)
import os

from celery import Celery
from decouple import config
from kombu.serialization import enable_insecure_serializers


enable_insecure_serializers(["pickle"])

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mprj_api.settings')

app = Celery(
    config('BROKER_QUEUE', 'lupa'),
    broker=config('BROKER_URL', default='redis://localhost:6379'),
    include=['dominio.alertas.tasks', 'mprjdigital.tasks'],
)
app.conf.timezone = 'UTC'
app.conf.task_default_queue = config('CELERY_TASK_QUEUE', None)
app.conf.event_serializer = 'pickle'
app.conf.task_serializer = 'pickle'
app.conf.accept_content = ['pickle']