Exemple #1
0
 def setup(self, app):
     for other in app.plugins:
         if not isinstance(other, MakoPlugin):
             continue
         if other.name == self.name:
             raise bottle.PluginError("Found another  MakoPlugin plugin with " \
                                      "conflicting settings (non-unique name).")
     if not self.lookup:
         raise bottle.PluginError('lookup value is None.')
 def setup(self, app):
     ''' Make sure that other installed plugins don't affect the same
         keyword argument and check if metadata is available.'''
     for other in app.plugins:
         if not isinstance(other, SQLAlchemyPlugin):
             continue
         if other.keyword == self.keyword:
             raise bottle.PluginError("Found another SQLAlchemy plugin with "\
                               "conflicting settings (non-unique keyword).")
     if self.create and not self.metadata:
         raise bottle.PluginError(
             'Define metadata value to create database.')
Exemple #3
0
 def setup(self, app):
     for other in app.plugins:
         if isinstance(other, LoggingPlugin):
             raise bottle.PluginError(
                 'Existing LoggingPlugin instance found.')
         elif getattr(other, 'keyword',
                      None) and other.keyword == self.keyword:
             raise bottle.PluginError(
                 'Keyword "{0}" conflicts with plugin "{1}".'.format(
                     self.keyword), other.name)
     _setup_root_logger(self.loglevel, self.logformat, self.logutc)
     self.exc_logger = _setup_exc_logger()
     self.logger = _setup_logger(self.loglevel)
Exemple #4
0
    def setup(self, app):

        for plugin in app.plugins:
            if not isinstance(plugin, ApiRedisPlugin):
                continue
            if plugin.keyword == self.keyword:
                raise bottle.PluginError('conflicting plugins')
Exemple #5
0
    def setup(self, app):  # pragma: no cover
        """Make sure that other installed plugins don't affect the same
        keyword argument and check if metadata is available.
        """

        if self.login_enable:

            #  Route a login handler in bottle.py app instance.
            @app.post(self.auth_endpoint)
            def auth_handler():
                try:
                    token, expires = self.provider.authenticate(bottle.request)
                    return {
                        "token": token.decode("utf-8"),
                        "expires": str(expires)
                    }

                except JWTAuthError as error:
                    return {"AuthError": error.args[0]}

                except JWTBackendError:
                    return {"AuthBackendError": "Try later or contact admin!"}

        for other in app.plugins:
            if not isinstance(other, JWTProviderPlugin):
                continue

            if other.keyword == self.keyword:
                raise bottle.PluginError("Found another JWT plugin "
                                         "with conflicting settings ("
                                         "non-unique keyword).")
Exemple #6
0
    def __init__(self, images_paths, path_thumbnails, keyword="mdb"):
        self.keyword = keyword

        try:
            self.mdb = MediaDatabase(images_paths, path_thumbnails)
        except MediaDatabaseError as e:
            raise bottle.PluginError("Unable to load media database: %s" % e)
Exemple #7
0
 def setup(self, app):
     for other in app.plugins:
         if not isinstance(other, MemcacheDecoratorPlugin):
             continue
         if other.memcache_expire_time_keyword == self.memcache_expire_time_keyword \
                 or other.memcache_compress_level_keyword == self.memcache_compress_level_keyword:
             raise bottle.PluginError("Found another memcache_decorator plugin with "\
                     "conflicting settings (non-unique keyword).")
Exemple #8
0
    def __init__(self, keyword, backend, **backend_kwargs):  # pragma: no cover

        if backend not in available_backend():
            raise bottle.PluginError(
                'Invalid backend {} provided. Available until now: ({})'.
                format(backend, ', '.join(available_backend().keys())))

        self.backend = available_backend()[backend](**backend_kwargs)
        self.keyword = keyword
Exemple #9
0
    def setup(self, app):
        for other in app.plugins:
            if not isinstance(other, MediaDatabasePlugin):
                continue

            if other.keyword == self.keyword:
                raise bottle.PluginError(
                    "Found another '%s' plugin with conflicting settings (non-unique keyword)."
                    % self.name)
Exemple #10
0
 def setup(self, app):
     """ Make sure that other installed plugins don't affect the same
         keyword argument and check if metadata is available."""
     for other in app.plugins:
         if not isinstance(other, BeakerPlugin):
             continue
         if other.keyword == self.keyword:
             raise bottle.PluginError("Found another beaker plugin "
                                      "with conflicting settings ("
                                      "non-unique keyword).")
 def setup(self,app):
     '''
     Make sure other installed plugins don't affect the same keyword
     argument
     '''
     for other in app.plugins:
         if not isinstance(other,MongoEnginePlugin): continue
         if other.keyword == self.keyword:
             raise bottle.PluginError("mongoengine plugin with "\
                               "conflicting settings (non-unique keyword)")
Exemple #12
0
 def setup(self, app):
     for other in app.plugins:
         if not isinstance(other, DBInjectorPlugin):
             continue
         if other.keyword == self.keyword:
             raise bottle.PluginError(
                 "Found another SQLAlchemy plugin with "
                 "conflicting settings (non-unique keyword).")
         elif other.name == self.name:
             self.name += '_%s' % self.keyword
Exemple #13
0
 def setup(self, app):  # pylint: disable=locally-disabled,no-self-use
     """
     Make sure that other installed plugins don't affect the same
     keyword argument and check if metadata is available.
     """
     for other in app.plugins:
         if not isinstance(other, ConfigPlugin):
             continue
         else:
             raise bottle.PluginError("Found another conflicting Config plugin.")
Exemple #14
0
 def setup(self, app):
     ''' Make sure that other installed plugins don't affect the same
         keyword argument.'''
     for other in app.plugins:
         if not isinstance(other, PeeweePlugin):
             continue
         if other.keyword == self.keyword:
             raise bottle.PluginError(
                 "Found another peewee plugin with "
                 "conflicting settings (non-unique keyword).")
Exemple #15
0
    def apply(self, callback, context):  # pragma: no cover
        """Implement bottle.py API version 2 `apply` method.
        """
        cache_enabled = getattr(callback, 'cache_info', None)

        if not cache_enabled:
            callback_args = inspect.getfullargspec(context.callback).args

            if self.keyword not in callback_args:
                return callback

            def _wrapped_injected(*args, **kwargs):
                kwargs[self.keyword] = self.backend
                return callback(*args, **kwargs)

            return _wrapped_injected

        if cache_enabled.cache_key_func not in self:
            raise bottle.PluginError('Unregistered cache key function: '
                                     '{}.'.format(
                                         cache_enabled.cache_key_func))

        def wrapper(*args, **kwargs):

            cache_key_fn = self.cache_key_rules[cache_enabled.cache_key_func]
            key = cache_key_fn(bottle.request, context)
            data = self.backend.get(key)

            if data:
                bottle.response.content_type = cache_enabled.content_type
                return ujson.loads(data)

            result = callback(*args, **kwargs)
            if result.status == "200 OK":
                self.backend.set(key, ujson.dumps(result.body),
                                 cache_enabled.ttl)
            return result

        return wrapper
Exemple #16
0
    def setup(self, app):  # pragma: no cover # noqa: C901 # (too complex)
        """Make sure that other installed plugins don't affect the same
        keyword argument and check if metadata is available.
        """

        if self.login_enable:
            #  Route a login handler in bottle.py app instance.
            @app.post(self.auth_endpoint)
            def auth_handler():
                try:
                    token, payload = self.provider.authenticate(bottle.request)
                    string_token = token.decode("utf-8")

                    if (self.provider.auth_redirect_rule is not None
                        ) and self.provider.auth_redirect_rule():
                        response = self.get_redirect_response_object(
                            self.provider.auth_redirect_to)

                        if self.provider.on_auth_redirect:
                            response = self.provider.on_auth_redirect(response)

                    else:
                        json_payload = {
                            "access_token": string_token,
                            "scope": payload["scope"],
                            "token_type": "bearer",
                            "expires_in": self.provider.ttl
                        }

                        response_headers = {
                            "Authorization": "Bearer " + string_token,
                            "Authorization-Scope": payload["scope"],
                            "Authorization-Token-Type": "bearer",
                            "Authorization-Expires-In": self.provider.ttl
                        }

                        response = HTTPResponse(status=200,
                                                body=json_payload,
                                                headers=response_headers)

                    response.set_cookie("Authorization",
                                        "Bearer " + string_token,
                                        max_age=self.provider.ttl,
                                        path=self.provider.cookie_path,
                                        secret=self.provider.cookie_secret)

                    return response

                except JWTAuthError as error:
                    return {"AuthError": error.args[0]}

                except JWTBackendError:
                    return {"AuthBackendError": "Try later or contact admin!"}

        for other in app.plugins:
            if not isinstance(other, JWTProviderPlugin):
                continue

            if other.keyword == self.keyword:
                raise bottle.PluginError("Found another JWT plugin "
                                         "with conflicting settings ("
                                         "non-unique keyword).")
Exemple #17
0
 def setup(self, app):
     for other in app.plugins:
         if not isinstance(other, ParamsPlugin):
             continue
         raise bottle.PluginError(
             "Found another ParamsPlugin be installed.")