Example #1
0
    def as_uri(self, include_password=False):
        """Return the backend as an URI.

        :keyword include_password: Censor passwords.

        """
        if include_password:
            return self.url

        if ',' not in self.url:
            return maybe_sanitize_url(self.url).rstrip('/')

        uri1, remainder = self.url.split(',', 1)
        return ','.join([maybe_sanitize_url(uri1).rstrip('/'), remainder])
Example #2
0
 def as_uri(self, include_password=False):
     """Return the backend as an URI, sanitizing the password or not"""
     # when using maybe_sanitize_url(), "/" is added
     # we're stripping it for consistency
     if self.url:
         return (self.url if include_password
                 else maybe_sanitize_url(self.url).rstrip("/"))
Example #3
0
    def as_uri(self, include_password=False):
        """Return the backend as an URI.

        Arguments:
            include_password (bool): Password censored if disabled.
        """
        if not self.url:
            return 'mongodb://'
        if include_password:
            return self.url

        if ',' not in self.url:
            return maybe_sanitize_url(self.url)

        uri1, remainder = self.url.split(',', 1)
        return ','.join([maybe_sanitize_url(uri1), remainder])
Example #4
0
def bugreport(app):
    """Return a string containing information useful in bug reports."""
    import billiard
    import celery
    import kombu

    try:
        conn = app.connection()
        driver_v = '{0}:{1}'.format(conn.transport.driver_name,
                                    conn.transport.driver_version())
        transport = conn.transport_cls
    except Exception:
        transport = driver_v = ''

    return BUGREPORT_INFO.format(
        system=_platform.system(),
        arch=', '.join(x for x in _platform.architecture() if x),
        py_i=pyimplementation(),
        celery_v=celery.VERSION_BANNER,
        kombu_v=kombu.__version__,
        billiard_v=billiard.__version__,
        py_v=_platform.python_version(),
        driver_v=driver_v,
        transport=transport,
        results=maybe_sanitize_url(app.conf.result_backend or 'disabled'),
        human_settings=app.conf.humanize(),
        loader=qualname(app.loader.__class__),
    )
Example #5
0
 def as_uri(self, include_password=False):
     """Return the backend as an URI, sanitizing the password or not"""
     # when using maybe_sanitize_url(), "/" is added
     # we're stripping it for consistency
     if include_password:
         return self.url
     url = maybe_sanitize_url(self.url or '')
     return url[:-1] if url.endswith(':///') else url
Example #6
0
 def as_uri(self, include_password=False):
     """Return the backend as an URI, sanitizing the password or not."""
     # when using maybe_sanitize_url(), "/" is added
     # we're stripping it for consistency
     if include_password:
         return self.url
     url = maybe_sanitize_url(self.url or '')
     return url[:-1] if url.endswith(':///') else url
Example #7
0
 def info(self):
     info = [
         '       . redis -> {}'.format(
             maybe_sanitize_url(self.app.redbeat_conf.redis_url))
     ]
     if self.lock_key:
         info.append('       . lock -> `{}` {} ({}s)'.format(
             self.lock_key, humanize_seconds(self.lock_timeout),
             self.lock_timeout))
     return '\n'.join(info)
Example #8
0
    def maybe_censor(key, value, mask='*' * 8):
        if isinstance(value, Mapping):
            return filter_hidden_settings(value)
        if isinstance(key, string_t):
            if HIDDEN_SETTINGS.search(key):
                return mask
            elif 'BROKER_URL' in key.upper():
                from kombu import Connection
                return Connection(value).as_uri(mask=mask)
            elif key.upper() in ('CELERY_RESULT_BACKEND', 'CELERY_BACKEND'):
                return maybe_sanitize_url(value, mask=mask)

        return value
Example #9
0
    def maybe_censor(key, value, mask='*' * 8):
        if isinstance(value, Mapping):
            return filter_hidden_settings(value)
        if isinstance(key, string_t):
            if HIDDEN_SETTINGS.search(key):
                return mask
            elif 'BROKER_URL' in key.upper():
                from kombu import Connection
                return Connection(value).as_uri(mask=mask)
            elif key.upper() in ('CELERY_RESULT_BACKEND', 'CELERY_BACKEND'):
                return maybe_sanitize_url(value, mask=mask)

        return value
Example #10
0
    def maybe_censor(key, value, mask='*' * 8):
        if isinstance(value, Mapping):
            return filter_hidden_settings(value)
        if isinstance(key, string_t):
            if HIDDEN_SETTINGS.search(key):
                return mask
            elif 'broker_url' in key.lower():
                from kombu import Connection
                return Connection(value).as_uri(mask=mask)
            elif 'backend' in key.lower():
                return maybe_sanitize_url(value, mask=mask)

        return value
Example #11
0
 def as_uri(self, include_password=False):
     """Return the server addresses as URIs, sanitizing the password or not."""
     # Allow superclass to do work if we don't need to force sanitization
     if include_password:
         return super().as_uri(include_password=include_password, )
     # Otherwise we need to ensure that all components get sanitized rather
     # by passing them one by one to the `kombu` helper
     uri_chunks = (maybe_sanitize_url(chunk) for chunk in (
         self.url or "").split(self._SERVER_URI_SEPARATOR))
     # Similar to the superclass, strip the trailing slash from URIs with
     # all components empty other than the scheme
     return self._SERVER_URI_SEPARATOR.join(
         uri[:-1] if uri.endswith(":///") else uri for uri in uri_chunks)
Example #12
0
    def maybe_censor(key, value, mask='*' * 8):
        if isinstance(value, Mapping):
            return filter_hidden_settings(value)
        if isinstance(key, string_t):
            if HIDDEN_SETTINGS.search(key):
                return mask
            elif 'broker_url' in key.lower():
                from kombu import Connection
                return Connection(value).as_uri(mask=mask)
            elif 'backend' in key.lower():
                return maybe_sanitize_url(value, mask=mask)

        return value
Example #13
0
    def startup_info(self):
        app = self.app
        concurrency = string(self.concurrency)
        appr = '{0}:{1:#x}'.format(app.main or '__main__', id(app))
        if not isinstance(app.loader, AppLoader):
            loader = qualname(app.loader)
            if loader.startswith('celery.loaders'):  # pragma: no cover
                loader = loader[14:]
            appr += ' ({0})'.format(loader)
        if self.autoscale:
            max, min = self.autoscale
            concurrency = '{{min={0}, max={1}}}'.format(min, max)
        pool = self.pool_cls
        if not isinstance(pool, string_t):
            pool = pool.__module__
        concurrency += ' ({0})'.format(pool.split('.')[-1])
        events = 'ON'
        if not self.send_events:
            events = 'OFF (enable -E to monitor this worker)'

        banner = BANNER.format(
            app=appr,
            hostname=safe_str(self.hostname),
            timestamp=datetime.now().replace(microsecond=0),
            version=VERSION_BANNER,
            conninfo=self.app.connection().as_uri(),
            results=maybe_sanitize_url(
                self.app.conf.result_backend or 'disabled',
            ),
            concurrency=concurrency,
            platform=safe_str(_platform.platform()),
            events=events,
            queues=app.amqp.queues.format(indent=0, indent_first=False),
        ).splitlines()

        # integrate the ASCII art.
        for i, x in enumerate(banner):
            try:
                banner[i] = ' '.join([ARTLINES[i], banner[i]])
            except IndexError:
                banner[i] = ' ' * 16 + banner[i]
        return '\n'.join(banner) + '\n'
Example #14
0
    def startup_info(self):
        app = self.app
        concurrency = string(self.concurrency)
        appr = '{0}:{1:#x}'.format(app.main or '__main__', id(app))
        if not isinstance(app.loader, AppLoader):
            loader = qualname(app.loader)
            if loader.startswith('celery.loaders'):  # pragma: no cover
                loader = loader[14:]
            appr += ' ({0})'.format(loader)
        if self.autoscale:
            max, min = self.autoscale
            concurrency = '{{min={0}, max={1}}}'.format(min, max)
        pool = self.pool_cls
        if not isinstance(pool, string_t):
            pool = pool.__module__
        concurrency += ' ({0})'.format(pool.split('.')[-1])
        events = 'ON'
        if not self.send_events:
            events = 'OFF (enable -E to monitor this worker)'

        banner = BANNER.format(
            app=appr,
            hostname=safe_str(self.hostname),
            version=VERSION_BANNER,
            conninfo=self.app.connection().as_uri(),
            results=maybe_sanitize_url(
                self.app.conf.result_backend or 'disabled',
            ),
            concurrency=concurrency,
            platform=safe_str(_platform.platform()),
            events=events,
            queues=app.amqp.queues.format(indent=0, indent_first=False),
        ).splitlines()

        # integrate the ASCII art.
        for i, x in enumerate(banner):
            try:
                banner[i] = ' '.join([ARTLINES[i], banner[i]])
            except IndexError:
                banner[i] = ' ' * 16 + banner[i]
        return '\n'.join(banner) + '\n'
Example #15
0
    def startup_info(self):
        app = self.app
        concurrency = string(self.concurrency)
        appr = "{0}:{1:#x}".format(app.main or "__main__", id(app))
        if not isinstance(app.loader, AppLoader):
            loader = qualname(app.loader)
            if loader.startswith("celery.loaders"):
                loader = loader[14:]
            appr += " ({0})".format(loader)
        if self.autoscale:
            max, min = self.autoscale
            concurrency = "{{min={0}, max={1}}}".format(min, max)
        pool = self.pool_cls
        if not isinstance(pool, string_t):
            pool = pool.__module__
        concurrency += " ({0})".format(pool.split(".")[-1])
        events = "ON"
        if not self.send_events:
            events = "OFF (enable -E to monitor this worker)"

        banner = BANNER.format(
            app=appr,
            hostname=safe_str(self.hostname),
            version=VERSION_BANNER,
            conninfo=self.app.connection().as_uri(),
            results=maybe_sanitize_url(self.app.conf.result_backend or "disabled"),
            concurrency=concurrency,
            platform=safe_str(_platform.platform()),
            events=events,
            queues=app.amqp.queues.format(indent=0, indent_first=False),
        ).splitlines()

        # integrate the ASCII art.
        for i, x in enumerate(banner):
            try:
                banner[i] = " ".join([ARTLINES[i], banner[i]])
            except IndexError:
                banner[i] = " " * 16 + banner[i]
        return "\n".join(banner) + "\n"
Example #16
0
def test_maybe_sanitize_url(url, expected):
    assert maybe_sanitize_url(url) == expected
    assert (maybe_sanitize_url('http://*****:*****@e.com//foo') ==
            'http://*****:*****@e.com//foo')
Example #17
0
 def test_maybe_sanitize_url(self):
     self.assertEqual(maybe_sanitize_url('foo'), 'foo')
     self.assertEqual(
         maybe_sanitize_url('http://*****:*****@e.com//foo'),
         'http://*****:*****@e.com//foo',
     )
Example #18
0
 def as_uri(self, include_password=False):
     """Return the backend as an URI, sanitizing the password or not"""
     # when using maybe_sanitize_url(), "/" is added
     # we're stripping it for consistency
     return (self.url if include_password else maybe_sanitize_url(
         self.url).rstrip("/"))
 def test_maybe_sanitize_url(self):
     self.assertEqual(maybe_sanitize_url('foo'), 'foo')
     self.assertEqual(
         maybe_sanitize_url('http://*****:*****@e.com//foo'),
         'http://*****:*****@e.com//foo',
     )