Beispiel #1
0
    def get_context(self):
        cfg = Config(SECURITY_KEY='ACME-SEC')
        cfg.LOADER = "thumbor.loaders.file_loader"
        cfg.FILE_LOADER_ROOT_PATH = self.loader_path

        cfg.RESULT_STORAGE = 'thumbor.result_storages.file_storage'
        cfg.RESULT_STORAGE_EXPIRATION_SECONDS = 60
        cfg.RESULT_STORAGE_FILE_STORAGE_ROOT_PATH = self.root_path

        cfg.SEND_IF_MODIFIED_LAST_MODIFIED_HEADERS = True

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(8889, 'localhost', 'thumbor.conf', None,
                                  'info', None)
        server.security_key = 'ACME-SEC'
        return Context(server, cfg, importer)
Beispiel #2
0
    def get_context(self):
        cfg = Config(SECURITY_KEY='ACME-SEC')
        cfg.LOADER = "thumbor.loaders.file_loader"
        cfg.FILE_LOADER_ROOT_PATH = self.loader_path
        cfg.FFMPEG_PATH = which('ffmpeg')
        cfg.OPTIMIZERS = [
            'thumbor.optimizers.gifv',
        ]

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(8889, 'localhost', 'thumbor.conf', None,
                                  'info', None)
        server.security_key = 'ACME-SEC'
        ctx = Context(server, cfg, importer)
        ctx.server.gifsicle_path = which('gifsicle')
        return ctx
Beispiel #3
0
    def get_context(self):
        cfg = Config(SECURITY_KEY='MYKEY')
        cfg.LOADER = "thumbor.loaders.file_loader"
        cfg.FILE_LOADER_ROOT_PATH = self.loader_path
        cfg.ALLOW_UNSAFE_URL = False
        cfg.ALLOW_OLD_URLS = True
        cfg.STORES_CRYPTO_KEY_FOR_EACH_IMAGE = True

        cfg.STORAGE = 'thumbor.storages.file_storage'
        cfg.STORAGE_FILE_STORAGE_ROOT_PATH = self.root_path

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(8891, 'localhost', 'thumbor.conf', None,
                                  'info', None)
        server.security_key = 'MYKEY'
        return Context(server, cfg, importer)
Beispiel #4
0
    def get_context(self):
        cfg = Config(SECURITY_KEY='ACME-SEC')
        cfg.LOADER = "thumbor.loaders.file_loader"
        cfg.FILE_LOADER_ROOT_PATH = self.loader_path
        cfg.JPEGTRAN_PATH = which('jpegtran')
        cfg.PROGRESSIVE_JPEG = True
        cfg.OPTIMIZERS = [
            'thumbor.optimizers.jpegtran',
        ]

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(8889, 'localhost', 'thumbor.conf', None,
                                  'info', None)
        server.security_key = 'ACME-SEC'
        ctx = Context(server, cfg, importer)
        return ctx
Beispiel #5
0
    def get_app(self):
        cfg = Config(SECURITY_KEY='ACME-SEC')
        cfg.LOADER = "thumbor.loaders.file_loader"
        cfg.FILE_LOADER_ROOT_PATH = storage_path
        cfg.AUTO_WEBP = True

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(8889, 'localhost', 'thumbor.conf', None,
                                  'info', None)
        server.security_key = 'ACME-SEC'
        ctx = Context(server, cfg, importer)
        application = ThumborServiceApp(ctx)

        self.engine = PILEngine(ctx)

        return application
    def get_context(self):
        cfg = Config(SECURITY_KEY="ACME-SEC")
        cfg.LOADER = "thumbor.loaders.file_loader"
        cfg.FILE_LOADER_ROOT_PATH = self.loader_path
        cfg.FFMPEG_PATH = which("ffmpeg")
        cfg.OPTIMIZERS = [
            "thumbor.optimizers.gifv",
        ]

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(8889, "localhost", "thumbor.conf", None,
                                  "info", None)
        server.security_key = "ACME-SEC"
        ctx = Context(server, cfg, importer)
        ctx.server.gifsicle_path = which("gifsicle")

        return ctx
    def get_app(self):
        cfg = Config(SECURITY_KEY='ACME-SEC', OPTIPNG_PATH=which('optipng'), OPTIPNG_LEVEL=1)
        cfg.LOADER = 'thumbor.loaders.file_loader'
        cfg.FILE_LOADER_ROOT_PATH = storage_path
        cfg.OPTIMIZERS = [
            'thumbor_plugins.optimizers.optipng',
        ]

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(8889, 'localhost', 'thumbor.conf', None, 'info', None)
        server.security_key = 'ACME-SEC'
        ctx = Context(server, cfg, importer)
        application = ThumborServiceApp(ctx)

        self.engine = PILEngine(ctx)

        return application
Beispiel #8
0
        def topic(self):
            config = Config()
            server = ServerParameters(
                8889, 'localhost', 'thumbor.conf', None, 'info', None
            )

            context = Context(server, config, Importer(config))
            context.server.gifsicle_path = which('gifsicle')

            context.request = RequestParameters()

            with open("%s/animated_image.gif" % FIXTURES_FOLDER, "rb") as f:
                buffer = f.read()

            engine = GifEngine(context=context)
            engine.load(buffer, '.gif')

            return engine.read()
Beispiel #9
0
    def get_app(self):
        cfg = Config(SECURITY_KEY='ACME-SEC')
        cfg.LOADER = "thumbor.loaders.file_loader"
        cfg.FILE_LOADER_ROOT_PATH = storage_path
        cfg.STORAGE = "thumbor.storages.file_storage"
        cfg.FILE_STORAGE_ROOT_PATH = FILE_STORAGE_ROOT_PATH
        if exists(FILE_STORAGE_ROOT_PATH):
            rmtree(FILE_STORAGE_ROOT_PATH)

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(8889, 'localhost', 'thumbor.conf', None,
                                  'info', None)
        server.security_key = 'ACME-SEC'
        ctx = Context(server, cfg, importer)
        application = ThumborServiceApp(ctx)

        return application
    def get_context(self):
        cfg = Config(SECURITY_KEY="ACME-SEC")
        cfg.LOADER = "thumbor.loaders.file_loader"
        cfg.FILE_LOADER_ROOT_PATH = self.loader_path
        cfg.RESULT_STORAGE = "thumbor.result_storages.file_storage"
        cfg.RESULT_STORAGE_EXPIRATION_SECONDS = 60
        cfg.RESULT_STORAGE_FILE_STORAGE_ROOT_PATH = self.root_path
        cfg.AUTO_WEBP = True

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(8889, "localhost", "thumbor.conf", None,
                                  "info", None)
        server.security_key = "ACME-SEC"
        ctx = Context(server, cfg, importer)
        ctx.request = self.get_request()
        ctx.server.gifsicle_path = which("gifsicle")
        return ctx
Beispiel #11
0
    def get_context(self):
        cfg = Config(SECURITY_KEY='ACME-SEC')
        cfg.LOADER = "thumbor.loaders.file_loader"
        cfg.FILE_LOADER_ROOT_PATH = '/tmp/path/that/does/not/exist'

        cfg.RESULT_STORAGE = 'thumbor.result_storages.file_storage'
        cfg.RESULT_STORAGE_EXPIRATION_SECONDS = 60
        cfg.RESULT_STORAGE_FILE_STORAGE_ROOT_PATH = self.root_path

        cfg.AUTO_WEBP = True

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(8889, 'localhost', 'thumbor.conf', None, 'info', None)
        server.security_key = 'ACME-SEC'
        ctx = Context(server, cfg, importer)

        return ctx
Beispiel #12
0
    def get_app(self):
        cfg = Config(SECURITY_KEY='ACME-SEC',
                     LOADER='thumbor.loaders.file_loader',
                     RESULT_STORAGE='thumbor.result_storages.file_storage',
                     RESULT_STORAGE_STORES_UNSAFE=True,
                     RESULT_STORAGE_EXPIRATION_SECONDS=2592000,
                     FILE_LOADER_ROOT_PATH=storage_path,
                     OPTIMIZERS=['thumbor.optimizers.jpegtran'])

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(8889, 'localhost', 'thumbor.conf', None,
                                  'info', None)
        server.security_key = 'ACME-SEC'
        ctx = Context(server, cfg, importer)
        application = ThumborServiceApp(ctx)

        return application
Beispiel #13
0
    def get_context(self):
        cfg = Config(SECURITY_KEY="ACME-SEC")
        cfg.LOADER = "thumbor.loaders.file_loader"
        cfg.FILE_LOADER_ROOT_PATH = self.loader_path
        cfg.JPEGTRAN_PATH = which("jpegtran")
        cfg.PROGRESSIVE_JPEG = (True,)
        cfg.RESULT_STORAGE_STORES_UNSAFE = (True,)
        cfg.OPTIMIZERS = [
            "thumbor.optimizers.jpegtran",
        ]

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(
            8889, "localhost", "thumbor.conf", None, "info", None
        )
        server.security_key = "ACME-SEC"
        ctx = Context(server, cfg, importer)
        return ctx
Beispiel #14
0
    def get_app(self):
        file_storage_root_path = '/tmp/thumbor-vows/storage'
        if exists(file_storage_root_path):
            rmtree(file_storage_root_path)

        cfg = Config()
        cfg.USE_BLACKLIST = True
        cfg.LOADER = "thumbor.loaders.file_loader"
        cfg.FILE_LOADER_ROOT_PATH = abspath(join(dirname(__file__), 'fixtures/'))
        cfg.STORAGE = 'thumbor.storages.file_storage'
        cfg.FILE_STORAGE_ROOT_PATH = file_storage_root_path

        importer = Importer(cfg)
        importer.import_modules()

        server = ServerParameters(8889, 'localhost', 'thumbor.conf', None, 'debug', None)
        ctx = Context(server, cfg, importer)
        application = ThumborServiceApp(ctx)
        return application
Beispiel #15
0
        def topic(self):
            port = 8890
            #use temporary file to store logs
            tmp = tempfile.NamedTemporaryFile(prefix='thumborTest.%i.' % port)

            cfg = Config(SECURITY_KEY='ACME-SEC',
                         ERROR_FILE_LOGGER=tmp.name.replace(
                             'thumborTest.%i.' % port, 'thumborTest.%i.'),
                         ERROR_FILE_NAME_USE_CONTEXT='server.port')
            server = ServerParameters(port, 'localhost', 'thumbor.conf', None,
                                      'info', None)
            server.security_key = 'ACME-SEC'
            ctx = Context(server, cfg, None)

            handler = ErrorHandler(cfg)
            http_handler = FakeHandler()

            handler.handle_error(ctx, http_handler, RuntimeError("Test"))
            #return content of file
            return tmp.read()
Beispiel #16
0
    async def test_should_raise_for_invalid_compatibility_storage(self):
        config = Config(
            FILE_LOADER_ROOT_PATH=STORAGE_PATH,
            STORES_CRYPTO_KEY_FOR_EACH_IMAGE=True,
        )
        importer = Importer(config)
        importer.import_modules()
        server = ServerParameters(8889, "localhost", "thumbor.conf", None,
                                  "info", None)
        server.security_key = "ACME-SEC"
        ctx = Context(server, config=config, importer=importer)
        storage = Storage(ctx)

        with expect.error_to_happen(
                RuntimeError,
                message=(
                    "The 'COMPATIBILITY_LEGACY_STORAGE' configuration should "
                    "point to a valid storage when using compatibility storage."
                ),
        ):
            await storage.get("invalid-path")
Beispiel #17
0
    def get_app(self):
        cfg = Config(
            SECURITY_KEY='ACME-SEC',
            LOADER='thumbor.loaders.file_loader',
            RESULT_STORAGE_STORES_UNSAFE=False,
            RESULT_STORAGE_EXPIRATION_SECONDS=2592000,
            FILE_LOADER_ROOT_PATH=storage_path,
            OPTIMIZERS=[],
            USE_GIFSICLE_ENGINE=True,
        )

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(8889, 'localhost', 'thumbor.conf', None,
                                  'info', None)
        server.security_key = 'ACME-SEC'
        server.gifsicle_path = which('gifsicle')
        ctx = Context(server, cfg, importer)
        application = ThumborServiceApp(ctx)

        return application
Beispiel #18
0
    def get_app(self):
        cfg = Config(SECURITY_KEY='MYKEY')
        cfg.LOADER = "thumbor.loaders.file_loader"
        cfg.FILE_LOADER_ROOT_PATH = storage_path
        cfg.ALLOW_UNSAFE_URL = False
        cfg.ALLOW_OLD_URLS = True
        cfg.STORES_CRYPTO_KEY_FOR_EACH_IMAGE = True

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(8891, 'localhost', 'thumbor.conf', None, 'info', None)
        server.security_key = 'MYKEY'
        ctx = Context(server, cfg, importer)
        application = ThumborServiceApp(ctx)

        storage = FileStorage(Context(config=cfg, server=server))

        # Store fixtures (image.jpg and image.txt) into the file storage
        storage.put('image.jpg', open(join(storage_path, 'image.jpg')).read())
        storage.put_crypto('image.jpg')   # Write a file on the file storage containing the security key

        return application
def start_thumbor():
    """
    Runs thumbor server with the specified arguments.
    """
    try:
        server_parameters = ServerParameters(
            port=8888,
            ip='0.0.0.0',
            config_path=None,
            keyfile=False,
            log_level=log_level,
            app_class='thumbor.app.ThumborServiceApp',
            use_environment=True)
        global config
        # SO-SIH-167 - 08/08/2018 - Allowing environment variable
        # Passing environment variable flag to server parameters
        config = get_config(thumbor_config_path,
                            server_parameters.use_environment)
        configure_log(config, server_parameters.log_level)
        importer = get_importer(config)
        os.environ["PATH"] += os.pathsep + '/var/task'
        validate_config(config, server_parameters)
        with get_context(server_parameters, config,
                         importer) as thumbor_context:
            application = get_application(thumbor_context)
            run_server(application, thumbor_context)
            tornado.ioloop.IOLoop.instance().start()
            logging.info(
                'thumbor running at %s:%d' %
                (thumbor_context.server.ip, thumbor_context.server.port))
            return config
    except RuntimeError as error:
        if str(error) != "IOLoop is already running":
            logging.error('start_thumbor RuntimeError: %s' % (error))
            stop_thumbor()
    except Exception as error:
        stop_thumbor()
        logging.error('start_thumbor error: %s' % (error))
        logging.error('start_thumbor trace: %s' % traceback.format_exc())
Beispiel #20
0
def context(config):
    config.ENGINE = 'thumbor_video_engine.engines.video'

    importer = Importer(config)
    importer.import_modules()

    server = ServerParameters(None,
                              'localhost',
                              'thumbor.conf',
                              None,
                              'info',
                              config.APP_CLASS,
                              gifsicle_path=which('gifsicle'))
    server.security_key = config.SECURITY_KEY

    req = RequestParameters()

    configure_log(config, 'DEBUG')

    with Context(server=server, config=config, importer=importer) as context:
        context.request = req
        context.request.engine = context.modules.engine
        yield context
Beispiel #21
0
    def test_can_create_server_parameters(self):
        params = ServerParameters(
            port=8888,
            ip='0.0.0.0',
            config_path='/tmp/config_path.conf',
            keyfile='./tests/fixtures/thumbor.key',
            log_level='debug',
            app_class='app',
            fd='fd',
            gifsicle_path='gifsicle_path',
        )

        expect(params.port).to_equal(8888)
        expect(params.ip).to_equal('0.0.0.0')
        expect(params.config_path).to_equal('/tmp/config_path.conf')
        expect(params.keyfile).to_equal('./tests/fixtures/thumbor.key')
        expect(params.log_level).to_equal('debug')
        expect(params.app_class).to_equal('app')
        expect(params._security_key).to_equal('SECURITY_KEY_FILE')
        expect(params.fd).to_equal('fd')
        expect(params.gifsicle_path).to_equal('gifsicle_path')

        expect(params.security_key).to_equal('SECURITY_KEY_FILE')
Beispiel #22
0
    def get_context(self):
        cfg = Config(SECURITY_KEY='ACME-SEC')
        cfg.LOADER = "thumbor.loaders.file_loader"
        cfg.FILE_LOADER_ROOT_PATH = '/tmp/path/that/does/not/exist'

        cfg.RESULT_STORAGE = 'thumbor.result_storages.file_storage'
        cfg.RESULT_STORAGE_EXPIRATION_SECONDS = 60
        cfg.RESULT_STORAGE_FILE_STORAGE_ROOT_PATH = self.root_path
        cfg.FFMPEG_PATH = which('ffmpeg')

        cfg.USE_GIFSICLE_ENGINE = True
        cfg.AUTO_WEBP = True
        cfg.OPTIMIZERS = [
            'thumbor.optimizers.gifv',
        ]

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(8889, 'localhost', 'thumbor.conf', None, 'info', None)
        server.security_key = 'ACME-SEC'
        ctx = Context(server, cfg, importer)
        ctx.server.gifsicle_path = which('gifsicle')

        return ctx
Beispiel #23
0
    def test_can_create_server_parameters():
        params = ServerParameters(
            port=8888,
            ip="0.0.0.0",
            config_path="/my/config_path.conf",
            keyfile="./tests/fixtures/thumbor.key",
            log_level="debug",
            app_class="app",
            fd="fd",
            gifsicle_path="gifsicle_path",
        )

        expect(params.port).to_equal(8888)
        expect(params.ip).to_equal("0.0.0.0")
        expect(params.config_path).to_equal("/my/config_path.conf")
        expect(params.keyfile).to_equal("./tests/fixtures/thumbor.key")
        expect(params.log_level).to_equal("debug")
        expect(params.app_class).to_equal("app")
        expect(params._security_key).to_equal(  # pylint: disable=protected-access
            "SECURITY_KEY_FILE")
        expect(params.fd).to_equal("fd")
        expect(params.gifsicle_path).to_equal("gifsicle_path")

        expect(params.security_key).to_equal("SECURITY_KEY_FILE")
    def get_context(self):
        cfg = Config(SECURITY_KEY='ACME-SEC')
        cfg.LOADER = "tests.stub_file_loader"
        cfg.STORAGE = "thumbor.storages.file_storage"
        cfg.FILE_STORAGE_ROOT_PATH = self.root_path
        cfg.QUALITY = 'keep'
        cfg.SVG_DPI = 200

        self.image = 'http://test.domain/image.jpg'
        self.quoted_image = quote(self.image, safe='')
        self.transform = '400x400/smart'
        self.signature = UrlSigner(security_key="ACME-SEC").signature(
            '%s/%s' % (self.transform, self.quoted_image))
        self.signed_prefix = "/%s/%s" % (self.signature, self.transform)
        self.full_image = "/%s/%s/%s" % (self.signature, self.transform,
                                         self.quoted_image)

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(
            8889, 'localhost', 'thumbor.conf', None, 'info',
            'thumbor_flexible_validation.app.ThumborServiceProxy')
        server.security_key = 'ACME-SEC'
        return Context(server, cfg, importer)
Beispiel #25
0
    def get_app(self):
        cfg = Config(SECURITY_KEY='ACME-SEC')
        server_params = ServerParameters(None, None, None, None, None, None)

        cfg.DETECTORS = [
            'thumbor.detectors.face_detector',
            'thumbor.detectors.profile_detector',
            'thumbor.detectors.glasses_detector',
            'thumbor.detectors.feature_detector',
        ]
        cfg.STORAGE = 'thumbor.storages.no_storage'
        cfg.LOADER = 'thumbor.loaders.file_loader'
        cfg.FILE_LOADER_ROOT_PATH = os.path.join(os.path.dirname(__file__),
                                                 'imgs')
        cfg.ENGINE = getattr(self, 'engine', None)
        if not cfg.ENGINE:
            return None

        importer = Importer(cfg)
        importer.import_modules()
        ctx = Context(server_params, cfg, importer)
        application = ThumborServiceApp(ctx)

        return application
Beispiel #26
0
 def get_server(self):
     server = ServerParameters(8889, 'localhost', 'thumbor.conf', None,
                               'info', None)
     server.security_key = 'ACME-SEC'
     return server
Beispiel #27
0
def get_server_parameters(arguments=None):
    if arguments is None:
        arguments = []

    parser = argparse.ArgumentParser(description="thumbor server")

    parser.add_argument(
        "--version",
        action="version",
        version="Thumbor v%s (%s)" % (__version__, __release_date__),
    )

    parser.add_argument(
        "-p",
        "--port",
        default=8888,
        type=int,
        help="The port to run this thumbor instance at [default: %(default)s].",
    )

    parser.add_argument(
        "-i",
        "--ip",
        default="0.0.0.0",
        help=
        "The host address to run this thumbor instance at [default: %(default)s].",
    )

    parser.add_argument(
        "-f",
        "--fd",
        help=
        "The file descriptor number or path to unix socket to listen for connections "
        "on (--port and --ip will be ignored if this is set)"
        "[default: %(default)s].",
    )

    parser.add_argument(
        "-c",
        "--conf",
        default=None,
        help="The path of the configuration file to use for this "
        "thumbor instance [default: %(default)s].",
    )

    parser.add_argument(
        "-k",
        "--keyfile",
        default=None,
        help="The path of the configuration file to use for this "
        "thumbor instance [default: %(default)s].",
    )

    parser.add_argument(
        "-l",
        "--log-level",
        default="warning",
        help="The log level to be used. Possible values are: "
        "debug, info, warning, error, critical or notset. "
        "[default: %(default)s].",
    )

    parser.add_argument(
        "-a",
        "--app",
        default="thumbor.app.ThumborServiceApp",
        help="A custom app to use for this thumbor server in case "
        "you subclassed ThumborServiceApp [default: %(default)s].",
    )

    parser.add_argument(
        "-d",
        "--debug",
        default=False,
        action="store_true",
        help="Debug mode [default: %(default)s].",
    )

    parser.add_argument(
        "--use-environment",
        default=False,
        help="Use environment variables for config",
    )

    parser.add_argument(
        "--processes",
        default=1,
        type=int,
        help=
        "Number of processes to run. By default 1 and means no forks created"
        "Set to 0 to detect the number of cores available on this machine"
        "Set > 1 to start that specified number of processes"
        "[default: %(default)s].",
    )

    options = parser.parse_args(arguments)

    return ServerParameters(
        port=options.port,
        ip=options.ip,
        config_path=options.conf,
        keyfile=options.keyfile,
        log_level=options.log_level,
        app_class=options.app,
        debug=options.debug,
        fd=options.fd,
        use_environment=options.use_environment,
        processes=options.processes,
    )
Beispiel #28
0
 def get_server(self):
     server = ServerParameters(8889, "localhost", "thumbor.conf", None,
                               "info", None)
     server.security_key = "ACME-SEC"
     return server
def get_server(key=None):
    server_params = ServerParameters(8888, 'localhost', 'thumbor.conf', None,
                                     'info', None)
    server_params.security_key = key
    return server_params
Beispiel #30
0
 def get_server(self):
     server = ServerParameters(8889, 'localhost', 'thumbor.conf', None,
                               'info', None)
     server.security_key = 'ACME-SEC'
     server.gifsicle_path = which('gifsicle')
     return server