def get_context(self):
        conf = Config()
        conf.STATSD_HOST = ''
        ctx = Context(config=conf)
        ctx.request = RequestParameters()

        return ctx
Exemple #2
0
            def topic(self):
                os.environ['SOME_CONFIGURATION'] = "test value"
                config = Config()

                Config.allow_environment_variables()

                return config.SOME_CONFIGURATION
Exemple #3
0
        def topic(self, callback):
            conf = Config()
            conf.define('TC_AWS_ALLOWED_BUCKETS', [], '')

            context = Context(config=conf)
            s3_loader.load(context, '/'.join([s3_bucket, IMAGE_PATH]),
                           callback)
 def test_zopflipng_should_not_run_when_unavailable(self):
     conf = Config()
     conf.ZOPFLIPNG_PATH = '/tmp/asdf'
     ctx = Context(config=conf)
     optimizer = ZopflipngOptimizer(ctx)
     self.assertFalse(optimizer.runnable)
     self.assertFalse(optimizer.should_run('png', None))
Exemple #5
0
            def topic(self):
                err = expect.error_to_happen(ConfigurationError)

                with err:
                    Config.load(fix('not-existent.conf'))

                return err
    def get_context(self):
        conf = Config()
        conf.STATSD_HOST = ''
        ctx = Context(config=conf)
        ctx.request = RequestParameters()

        return ctx
Exemple #7
0
            def topic(self):
                err = expect.error_to_happen(ConfigurationError)

                with err:
                    Config.load(fix('not-existent.conf'))

                return err
Exemple #8
0
            def topic(self):
                os.environ['SOME_CONFIGURATION'] = "test value"
                config = Config()

                Config.allow_environment_variables()

                return config.SOME_CONFIGURATION
    def get_context(self):
        conf = Config()
        conf.STATSD_HOST = ''
        ctx = Context(config=conf)
        ctx.request = RequestParameters()
        ctx.request.filters.append('auto')

        return ctx
    def get_context(self):
        conf = Config()
        conf.STATSD_HOST = ''
        ctx = Context(config=conf)
        ctx.request = RequestParameters()
        ctx.request.filters.append('auto')

        return ctx
Exemple #11
0
            def topic(self):
                config = Config.load(fix('sample.conf'))
                Config.allow_environment_variables()

                try:
                    os.environ['FOO'] = "baz"
                    return config.FOO
                finally:
                    del os.environ['FOO']
Exemple #12
0
            def topic(self):
                config = Config.load(fix('sample.conf'))
                Config.allow_environment_variables()

                try:
                    os.environ['FOO'] = "baz"
                    return config.FOO
                finally:
                    del os.environ['FOO']
Exemple #13
0
        def topic(self):
            conn = boto.connect_s3()
            bucket = conn.create_bucket(s3_bucket)

            k = Key(bucket)
            k.key = IMAGE_PATH
            k.set_contents_from_string(IMAGE_BYTES)

            conf = Config()
            conf.define('S3_LOADER_BUCKET', s3_bucket, '')
            conf.define('S3_LOADER_ROOT_PATH', 'root_path', '')

            return Context(config=conf)
Exemple #14
0
        def topic(self, callback):
            conn = boto.connect_s3()
            bucket = conn.create_bucket(s3_bucket)

            k = Key(bucket)
            k.key = '/'.join(['root_path', IMAGE_PATH])
            k.set_contents_from_string(IMAGE_BYTES)

            conf = Config()
            conf.define('TC_AWS_LOADER_BUCKET', s3_bucket, '')
            conf.define('TC_AWS_LOADER_ROOT_PATH', 'root_path', '')

            context = Context(config=conf)

            s3_loader.load(context, IMAGE_PATH, callback)
Exemple #15
0
    def load(self, config_path=None):
        """
        Load configuration from file. If no config path is given, several
        directories are searched for a file named 'githubsurvivor.conf': the
        current directory, followed by the current user's home directory, then
        finally /etc.
        """
        if not config_path:
            config_path = c.get_conf_file(self.DEFAULT_FILENAME, self.SEARCH_DIRS)

        if not config_path:
            raise Exception(
                'No configuration provided, and none found at any of %s' % \
                    ', '.join(path.join(d, self.DEFAULT_FILENAME) for d in self.SEARCH_DIRS))

        self._config = c.load(config_path or self._default_path())
Exemple #16
0
    def load(self, config_path=None):
        """
        Load configuration from file. If no config path is given, several
        directories are searched for a file named 'githubsurvivor.conf': the
        current directory, followed by the current user's home directory, then
        finally /etc.
        """
        if not config_path:
            config_path = c.get_conf_file(self.DEFAULT_FILENAME, self.SEARCH_DIRS)

        if not config_path:
            raise Exception(
                'No configuration provided, and none found at any of %s' % \
                    ', '.join(path.join(d, self.DEFAULT_FILENAME) for d in self.SEARCH_DIRS))

        self._config = c.load(config_path or self._default_path())
    def test_can_validate_buckets(self):
        conf = Config(
            TC_AWS_ALLOWED_BUCKETS=['whitelist_bucket'],
            TC_AWS_LOADER_BUCKET=None,
        )

        image = yield presigning_loader.load(Context(config=conf),
                                             '/'.join([s3_bucket, IMAGE_PATH]))
        self.assertIsNone(image)
    def test_should_use_http_loader(self, load_sync_patch):
        def cb(a, b, callback, *args, **kwargs):
            callback('foobar')
            return None

        load_sync_patch.side_effect = cb

        conf = Config(TC_AWS_ENABLE_HTTP_LOADER=True)
        presigning_loader.load(Context(config=conf), 'http://foo.bar')
        self.assertTrue(load_sync_patch.called)
Exemple #19
0
 def topic(self, callback):
     conf = Config(TC_AWS_ENDPOINT_URL='http://test.example.com:9000',
                   TC_AWS_CONFIG={
                       's3': {
                           'addressing_style': 'path'
                       },
                       'signature_version': 's3v4'
                   })
     context = Context(config=conf)
     presigning_loader._generate_presigned_url(context, "bucket-name",
                                               "some-s3-key", callback)
Exemple #20
0
    def test_can_load_image(self):
        client = botocore.session.get_session().create_client('s3')
        client.create_bucket(Bucket=s3_bucket)

        client.put_object(
            Bucket=s3_bucket,
            Key=''.join(['root_path', IMAGE_PATH]),
            Body=IMAGE_BYTES,
            ContentType='image/jpeg',
        )

        conf = Config(TC_AWS_LOADER_BUCKET=s3_bucket,
                      TC_AWS_LOADER_ROOT_PATH='root_path')

        image = yield s3_loader.load(Context(config=conf), IMAGE_PATH)
        self.assertEqual(image, IMAGE_BYTES)
Exemple #21
0
        def topic(self):
            conn = boto.connect_s3()
            bucket = conn.create_bucket(s3_bucket)

            k = Key(bucket)
            k.key = IMAGE_PATH
            k.set_contents_from_string(IMAGE_BYTES)

            conf = Config()
            conf.define('TC_AWS_LOADER_BUCKET', s3_bucket, '')
            conf.define('TC_AWS_LOADER_ROOT_PATH', 'root_path', '')

            return Context(config=conf)
    def test_can_build_presigned_url(self):
        context = Context(config=(Config()))
        url = yield presigning_loader._generate_presigned_url(
            context, "bucket-name", "some-s3-key")

        url = urlparse(url)
        self.assertEqual(url.scheme[0:4], 'http')
        self.assertEqual(url.path, '/bucket-name/some-s3-key')

        url_params = parse_qs(url.query)
        # We can't test Expires & Signature values as they vary depending on the TZ
        self.assertIn('Expires', url_params)
        self.assertIn('Signature', url_params)

        self.assertDictContainsSubset(
            {
                'AWSAccessKeyId': ['test-key'],
                'x-amz-security-token': ['test-session-token']
            }, url_params)
        def topic(self, callback):
            conn = boto.connect_s3()
            bucket = conn.create_bucket(s3_bucket)

            k = Key(bucket)
            k.key = '/'.join(['root_path', IMAGE_PATH])
            k.set_contents_from_string(IMAGE_BYTES)

            conf = Config()
            conf.define('TC_AWS_LOADER_BUCKET', s3_bucket, '')
            conf.define('TC_AWS_LOADER_ROOT_PATH', 'root_path', '')

            context = Context(config=conf)

            s3_loader.load(context, IMAGE_PATH, callback)
Exemple #24
0
 def topic(self):
     return Config.load(None, conf_name='sample.conf', lookup_paths=['vows/fixtures/'])
Exemple #25
0
 def topic(self):
     Config.alias('LOADER_ALIAS', 'LOADER')
     return Config(LOADER='y')
Exemple #26
0
# -*- coding: utf-8 -*-

# thumbor imaging service
# https://github.com/globocom/thumbor/wiki

# Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license
# Copyright (c) 2011 globo.com [email protected]

from os.path import join
import tempfile
import derpconf.config as config
from derpconf.config import Config

Config.define(
    'THUMBOR_LOG_FORMAT', '%(asctime)s %(name)s:%(levelname)s %(message)s',
    'Log Format to be used by thumbor when writing log messages.', 'Logging')

Config.define(
    'THUMBOR_LOG_DATE_FORMAT', '%Y-%m-%d %H:%M:%S',
    'Date Format to be used by thumbor when writing log messages.', 'Logging')

Config.define('MAX_WIDTH', 0, "Max width in pixels for images read or generated by thumbor", 'Imaging')
Config.define('MAX_HEIGHT', 0, "Max height in pixels for images read or generated by thumbor", 'Imaging')
Config.define('MIN_WIDTH', 1, "Min width in pixels for images read or generated by thumbor", 'Imaging')
Config.define('MIN_HEIGHT', 1, "Min width in pixels for images read or generated by thumbor", 'Imaging')
Config.define('ALLOWED_SOURCES', [], "Allowed domains for the http loader to download. These are regular expressions.", 'Imaging')
Config.define('QUALITY', 80, 'Quality index used for generated JPEG images', 'Imaging')
Config.define('MAX_AGE', 24 * 60 * 60, 'Max AGE sent as a header for the image served by thumbor in seconds', 'Imaging')
Config.define(
    'MAX_AGE_TEMP_IMAGE', 0,
Exemple #27
0
 def topic(self, callback):
     conf = Config()
     context = Context(config=conf)
     presigning_loader._generate_presigned_url(context, "bucket-name",
                                               "some-s3-key", callback)
Exemple #28
0
import derpconf.config as config
from derpconf.config import Config

#Config.define('MY-KEY', 'DEFAULT VALUE', 'Description for my key', 'Section')
Config.define('PORT', '12345', 'Listened port', 'Application')
Config.define('TEMPLATE_DIR', '.', 'tempalte files directory', 'Template')
Config.define('DATABASE', 'database-demo', 'unuseful, just for demo',
              'Useless')

if __name__ == '__main__':
    config.generate_config()
Exemple #29
0
 def topic(self):
     return Config.load(None,
                        defaults={'DEFAULT': 'DEFAULTVALUE'})
Exemple #30
0
 def topic(self):
     Config.alias('OTHER_ENGINE', 'ENGINE')
     return Config(OTHER_ENGINE='x')
Exemple #31
0
extension = Extension('tc_shortener')

# Register the required modules
extension.add_module(
    config_key='SHORTENER_GENERATOR',
    class_name='Generator',
    multiple=False
)

extension.add_module(
    config_key='SHORTENER_STORAGE',
    class_name='Storage',
    multiple=False
)

Config.define('SHORTENER_GENERATOR', 'tc_shortener.generators.short_generator',  'Shortened URL generator class.', 'Shortener')
Config.define('SHORTENER_STORAGE',   'tc_shortener.storages.redis_storage',      'Shortened URL storage.',         'Shortener')

Config.define('SHORTENER_GENERATOR_PRESERVE_NAME', True, 'Should the URL generator preserve the image name in the URL?', 'Shortener')

Config.define('SHORTENER_REDIS_STORAGE_SERVER_HOST',     'localhost', 'Redis hostname.',           'Shortener')
Config.define('SHORTENER_REDIS_STORAGE_SERVER_PORT',     6379,        'Redis port.',               'Shortener')
Config.define('SHORTENER_REDIS_STORAGE_SERVER_PASSWORD', None,        'Redis password.',           'Shortener')
Config.define('SHORTENER_REDIS_STORAGE_SERVER_DB',       0,           'Redis db name (optional).', 'Shortener')

# Register the route
extension.add_handler(UrlShortenerHandler.regex(), UrlShortenerHandler)

Extensions.register(extension)
Exemple #32
0
# thumbor imaging service
# https://github.com/globocom/thumbor/wiki

# Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license
# Copyright (c) 2011 globo.com [email protected]

from os.path import join
import tempfile

import derpconf.config as config
from derpconf.config import Config

from thumbor import __version__

Config.define('THUMBOR_LOG_CONFIG', None, 'Logging configuration as json', 'Logging')
Config.define(
    'THUMBOR_LOG_FORMAT', '%(asctime)s %(name)s:%(levelname)s %(message)s',
    'Log Format to be used by thumbor when writing log messages.', 'Logging')

Config.define(
    'THUMBOR_LOG_DATE_FORMAT', '%Y-%m-%d %H:%M:%S',
    'Date Format to be used by thumbor when writing log messages.', 'Logging')

Config.define(
  'STATSD_HOST', None,
  'Host to send statsd instrumentation to', 'Logging')

Config.define(
  'STATSD_PREFIX', None,
  'Prefix for statsd', 'Logging')
        def topic(self):

            conf = Config()
            conf.define('TC_AWS_MAX_RETRIES', 3, '')
            return Context(config=conf)
Exemple #34
0
 def topic(self):
     conf = Config()
     return Context(config=conf)
Exemple #35
0
        def topic(self):
            conf = Config()
            conf.define('AWS_ENABLE_HTTP_LOADER', True, '')

            return Context(config=conf)
Exemple #36
0
        def topic(self):
            conf = Config()
            conf.define('S3_ALLOWED_BUCKETS', [], '')

            return Context(config=conf)
Exemple #37
0
 def topic(self):
     return Config.load(
         None, conf_name='not-existent.conf',
         lookup_paths=['vows/fixtures/'],
         defaults={'DEFAULT': 'DEFAULTVALUE'}
     )
Exemple #38
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-


import derpconf.config as config
from derpconf.config import Config


Config.define('APPLICATION_URL', 'http://0.0.0.0:8080', 'The url to access the running application.', 'General')

Config.define('JSONP_CALLBACK', 'impimCallback', 'Default callback for JSONP responses.', 'General')

Config.define('IMAGES_STORAGE', 'impim_api.domain.storage.FileSystem', 'Defines where the images will be stored.', 'General')
Config.define('METADATA_STORAGE', 'impim_api.domain.storage.ElasticSearch', 'Defines where the metadata will be stored.', 'General')

Config.define('ELASTIC_SEARCH_BASE_URL', 'http://localhost:9200', 'ElasticSearch base url.', 'ElasticSearch')
Config.define('ELASTIC_SEARCH_INDEX', 'impim', 'ElasticSearch index.', 'ElasticSearch')

Config.define('FILE_SYSTEM_ROOT_PATH', '/tmp/impim-api', 'File System root path.', 'File System Storage')

Config.define('AWS_ACCESS_KEY_ID', 'xxx', 'The amazon access key.', 'AWS')
Config.define('AWS_SECRET_ACCESS_KEY', 'yyy', 'The amazon secret key.', 'AWS')
Config.define('AWS_BUCKET_NAME', 'my_bucket', 'The S3 bucket name.', 'AWS')

Config.define('THUMBOR_SECURITY_KEY', 'MY_SECURE_KEY', 'Thumbor security key.', 'Thumbor configuration')
Config.define('THUMBOR_SERVER_URL', 'http://localhost:8888/', 'Thumbor server url.', 'Thumbor configuration')


def generate_config():
    config.generate_config()
Exemple #39
0
 def topic(self):
     return Config.load(None, defaults={'DEFAULT': 'DEFAULTVALUE'})
    def get_context(self):
        conf = Config()
        conf.PNGCRUSH_PATH = self.pngcrush_path
        conf.STATSD_HOST = ''

        return Context(config=conf)
Exemple #41
0
 def topic(self):
     Config.alias('LOADER_ALIAS', 'LOADER')
     return Config(LOADER='y')
Exemple #42
0
def get_handlers(conf):
    DEFAULT_CONF = {'conf': conf, 'middleware_list': get_middleware_list()}

    return [
        url(r"/", HelloTornadoHandler, DEFAULT_CONF),
        url(r"/story/([0-9]+)", StoryHandler, DEFAULT_CONF, name="story"),
        url(r"/login_error",
            LoginErrorHandler,
            DEFAULT_CONF,
            name="login_error"),
    ]


class HelloTornadoApplication(tornado.web.Application):
    def __init__(self, handlers, settings):
        super(HelloTornadoApplication, self).__init__(handlers, settings)


def make_app(conf, handlers):
    return HelloTornadoApplication(
        handlers=handlers,
        settings={'template_path': conf.TEMPLATE_DIR},
    )


if __name__ == '__main__':
    conf = Config.load('settings.conf')
    app = make_app(conf, get_handlers(conf))
    app.listen(conf.PORT)
    tornado.ioloop.IOLoop.current().start()
    def get_context(self):
        conf = Config()
        conf.ZOPFLIPNG_PATH = self.zopflipng_path
        conf.STATSD_HOST = ''

        return Context(config=conf)
Exemple #44
0
 def topic(self):
     return Config.load(fix('sample.conf'))
Exemple #45
0
 def topic(self):
     Config.define('some_key', 'default', 'test key')
     return Config.load(fix('missing.conf'))
Exemple #46
0
 def topic(self):
     return Config.load(None,
                        conf_name='not-existent.conf',
                        lookup_paths=['vows/fixtures/'],
                        defaults={'DEFAULT': 'DEFAULTVALUE'})
    def get_context(self):
        conf = Config()
        conf.OPTIPNG_PATH = self.optipng_path
        conf.STATSD_HOST = ''

        return Context(config=conf)
Exemple #48
0
 def topic(self):
     return Config.load(None,
                        conf_name='sample.conf',
                        lookup_paths=['vows/fixtures/'])
Exemple #49
0
        def topic(self):
            conf = Config()
            conf.define('TC_AWS_ALLOWED_BUCKETS', [], '')

            return Context(config=conf)
Exemple #50
0
 def topic(self):
     return Config.load(fix('sample.conf'),
                        defaults={'PROPER': 'PROPERVALUE'})
Exemple #51
0
# thumbor imaging service
# https://github.com/globocom/thumbor/wiki

# Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license
# Copyright (c) 2011 globo.com [email protected]

from os.path import join
import tempfile

import derpconf.config as config
from derpconf.config import Config

from thumbor import __version__

Config.define('THUMBOR_LOG_CONFIG', None, 'Logging configuration as json',
              'Logging')
Config.define('THUMBOR_LOG_FORMAT',
              '%(asctime)s %(name)s:%(levelname)s %(message)s',
              'Log Format to be used by thumbor when writing log messages.',
              'Logging')

Config.define('THUMBOR_LOG_DATE_FORMAT', '%Y-%m-%d %H:%M:%S',
              'Date Format to be used by thumbor when writing log messages.',
              'Logging')

Config.define('STATSD_HOST', None, 'Host to send statsd instrumentation to',
              'Logging')

Config.define('STATSD_PREFIX', None, 'Prefix for statsd', 'Logging')

Config.define('MAX_WIDTH', 0,
Exemple #52
0
 def topic(self):
     return Config.load(fix('sample.conf'), defaults={
         'PROPER': 'PROPERVALUE'
     })
# -*- coding: utf-8 -*-
# System imports
# Third-party imports
from derpconf.config import Config
from tc_core import Extension, Extensions

# Local imports
from thumbor_aliases.handlers.aliases import UrlAliasesHandler

extension = Extension('thumbor_aliases')

# Register modules for settings
extension.add_module(config_key='ALIASES_STORAGE',
                     class_name='AliasesStorage',
                     multiple=False)

# Register main handler
extension.add_handler(UrlAliasesHandler.regex(), UrlAliasesHandler)

# Define settings
Config.define('ALIASES_STORAGE', 'thumbor_aliases.storages.yml_file',
              'Aliases storage class', 'URL Aliases')
Config.define('ALIASES_STORAGE_FILE', '~/aliases.yml', 'Aliases file name')

Extensions.register(extension)
Exemple #54
0
 def topic(self):
     Config.alias('OTHER_ENGINE', 'ENGINE')
     return Config(OTHER_ENGINE='x')
        def topic(self):
            conf = Config()
            conf.define('TC_AWS_ENABLE_HTTP_LOADER', True, '')

            return Context(config=conf)
Exemple #56
0
#!/usr/bin/python
# -*- coding: utf-8 -*-

from derpconf.config import Config  # NOQA

Config.define(
    'STORAGE',
    'gaas.storage.sqlalchemy.SqlAlchemyStorage',
    'Storage to be used when saving information about repositories or users',
    'Storage'
)

Config.define('MONGO_DATABASES', {
    'default': {
        'host': 'localhost',
        'port': 4445,
        'database': 'gaas',
    }
}, 'MongoDB Database connection.', 'Database')

Config.define(
    'GIT_ROOT',
    '/tmp/gaas/gitroot',
    'Root folder to store git repositories.',
    'Git'
)
Exemple #57
0
# -*- coding: utf-8 -*-

# thumbor imaging service
# https://github.com/globocom/thumbor/wiki

# Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license
# Copyright (c) 2011 globo.com [email protected]

from os.path import join
import tempfile
import derpconf.config as config
from derpconf.config import Config


Config.define("MAX_WIDTH", 0, "Max width in pixels for images read or generated by thumbor", "Imaging")
Config.define("MAX_HEIGHT", 0, "Max height in pixels for images read or generated by thumbor", "Imaging")
Config.define("MIN_WIDTH", 1, "Min width in pixels for images read or generated by thumbor", "Imaging")
Config.define("MIN_HEIGHT", 1, "Min width in pixels for images read or generated by thumbor", "Imaging")
Config.define(
    "ALLOWED_SOURCES", [], "Allowed domains for the http loader to download. These are regular expressions.", "Imaging"
)
Config.define("QUALITY", 80, "Quality index used for generated JPEG images", "Imaging")
Config.define("MAX_AGE", 24 * 60 * 60, "Max AGE sent as a header for the image served by thumbor in seconds", "Imaging")
Config.define(
    "MAX_AGE_TEMP_IMAGE",
    0,
    "Indicates the Max AGE header in seconds for temporary images (images that haven't been detected yet)",
    "Imaging",
)
Config.define(
Exemple #58
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# this file is part of level.
# https://github.com/heynemann/level

# licensed under the mit license:
# http://www.opensource.org/licenses/mit-license
# copyright (c) 2016, bernardo heynemann <*****@*****.**>


import derpconf.config as config
from derpconf.config import Config

Config.define('LEVEL_LOG_CONFIG', None, 'Logging configuration as json', 'Logging')
Config.define(
    'LEVEL_LOG_FORMAT', '%(asctime)s %(name)s:%(levelname)s %(message)s',
    'Log Format to be used by level when writing log messages.', 'Logging'
)

Config.define(
    'LEVEL_LOG_DATE_FORMAT', '%Y-%m-%d %H:%M:%S',
    'Date Format to be used by level when writing log messages.', 'Logging'
)

Config.define(
    'APP_CLASS', 'level.app.LevelApp',
    'Custom app class to override LevelApp.', 'WebServer',
)

Config.define(
Exemple #59
0
import sys

from derpconf.config import Config


def INSTANCE(x):
    return os.path.join(os.path.dirname(__file__), x)


if 'test' in sys.argv:
    config_file = INSTANCE('tests.config')
else:
    config_file = INSTANCE('local.config')

if os.path.isfile(config_file):
    conf = Config.load(config_file)
else:
    conf = Config()

DEBUG = conf.get('DEBUG', True)

ADMINS = conf.get('ADMINS', ())

MANAGERS = ADMINS

DEAFAULT_DATABASE = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': INSTANCE('db.sqlite3'),
        'USER': '',
        'PASSWORD': '',
Exemple #60
0
 def topic(self):
     Config.alias('STORAGE_ALIAS', 'STORAGE')
     Config.alias('STORAGE_ALIAS_ALIAS', 'STORAGE_ALIAS')
     return Config(STORAGE_ALIAS_ALIAS='z')