def get_context(self): conf = Config() conf.STATSD_HOST = '' ctx = Context(config=conf) ctx.request = RequestParameters() return ctx
def topic(self): os.environ['SOME_CONFIGURATION'] = "test value" config = Config() Config.allow_environment_variables() return config.SOME_CONFIGURATION
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))
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() ctx.request.filters.append('auto') return ctx
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']
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)
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)
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)
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)
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)
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): return Config.load(None, conf_name='sample.conf', lookup_paths=['vows/fixtures/'])
def topic(self): Config.alias('LOADER_ALIAS', 'LOADER') return Config(LOADER='y')
# -*- 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,
def topic(self, callback): conf = Config() context = Context(config=conf) presigning_loader._generate_presigned_url(context, "bucket-name", "some-s3-key", callback)
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()
def topic(self): return Config.load(None, defaults={'DEFAULT': 'DEFAULTVALUE'})
def topic(self): Config.alias('OTHER_ENGINE', 'ENGINE') return Config(OTHER_ENGINE='x')
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)
# 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)
def topic(self): conf = Config() return Context(config=conf)
def topic(self): conf = Config() conf.define('AWS_ENABLE_HTTP_LOADER', True, '') return Context(config=conf)
def topic(self): conf = Config() conf.define('S3_ALLOWED_BUCKETS', [], '') return Context(config=conf)
def topic(self): return Config.load( None, conf_name='not-existent.conf', lookup_paths=['vows/fixtures/'], defaults={'DEFAULT': 'DEFAULTVALUE'} )
#!/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()
def get_context(self): conf = Config() conf.PNGCRUSH_PATH = self.pngcrush_path conf.STATSD_HOST = '' return Context(config=conf)
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)
def topic(self): return Config.load(fix('sample.conf'))
def topic(self): Config.define('some_key', 'default', 'test key') return Config.load(fix('missing.conf'))
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)
def topic(self): conf = Config() conf.define('TC_AWS_ALLOWED_BUCKETS', [], '') return Context(config=conf)
def topic(self): return Config.load(fix('sample.conf'), defaults={'PROPER': 'PROPERVALUE'})
# 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,
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)
def topic(self): conf = Config() conf.define('TC_AWS_ENABLE_HTTP_LOADER', True, '') return Context(config=conf)
#!/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' )
# -*- 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(
#!/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(
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': '',
def topic(self): Config.alias('STORAGE_ALIAS', 'STORAGE') Config.alias('STORAGE_ALIAS_ALIAS', 'STORAGE_ALIAS') return Config(STORAGE_ALIAS_ALIAS='z')