Exemple #1
0
    def can_load(self, raw, cls):
        temp, options = write_temp_file(raw)

        cfg = aumbry.load(aumbry.FILE, cls, options)
        os.remove(temp.name)

        expect(cfg.nope).to.equal('testing')
Exemple #2
0
def main():
    docopt(__doc__)

    cfg = aumbry.load(
        aumbry.FILE,
        sysconfig.AppConfig,
        {
            'CONFIG_FILE_PATH': './config/platform/config.yml'
        }
    )
    
    managercfg={}
    managerConfig= configmanager.ConfigManager('./config/manager.conf')
    managercfg['manager']=managerConfig
    
    triggerConfig= configmanager.ConfigManager('./config/triggermanager.conf')
    managercfg['trigger']=triggerConfig
    #print triggerConfig.get_key('trigger','test_dis')
   
    displayConfig = configmanager.ConfigManager('./config/display.conf') 
    managercfg['display']=displayConfig    

    api_app = MyService(managercfg)
    gunicorn_app = GunicornApp(api_app, cfg.gunicorn)

    gunicorn_app.run()
Exemple #3
0
    def can_use_yaml_cfg_with_handler_override(self):
        with mock_ssm():
            options = {
                'PARAMETER_STORE_AWS_REGION': 'us-west-2',
                'PARAMETER_STORE_PREFIX': '/aumbry-test',
            }

            expected_cfg = SampleYamlConfig()
            expected_cfg.nope = 'testing'

            handler = GenericHandler()

            # Save Sample Config
            aumbry.save(aumbry.PARAM_STORE,
                        expected_cfg,
                        options,
                        handler=handler)

            # Retrieve back the config
            cfg = aumbry.load(aumbry.PARAM_STORE,
                              SampleGenericConfig,
                              options,
                              handler=handler)

        expect(cfg.nope).to.equal(expected_cfg.nope)
Exemple #4
0
def command(arguments):
    options = build_options(arguments)
    file_path = arguments.path
    input_handler = JsonHandler()
    output_handler = None

    if arguments.file_type == 'yml':
        input_handler = YamlHandler()

    if arguments.dest == aumbry.PARAM_STORE:
        output_handler = GenericHandler()

    if not has_required(arguments.dest, options):
        print('Missing required options for destination type')
        return 1

    package_ref, _, name = arguments.config_class.partition(':')
    if not name:
        print('config_class: requires a package and class reference')
        print('Example: my_package.sub:AppConfig')
        return 1

    with PikeManager([arguments.package_root]):
        module = py.get_module_by_name(package_ref)
        config_cls = getattr(module, name)

        print('Loading Config File...')
        cfg = aumbry.load(aumbry.FILE,
                          config_cls, {'CONFIG_FILE_PATH': file_path},
                          handler=input_handler)

        print('Uploading Config...')
        aumbry.save(arguments.dest, cfg, options, handler=output_handler)
Exemple #5
0
def main():
    docopt(__doc__)

    cfg = aumbry.load(aumbry.FILE, AppConfig,
                      {'CONFIG_FILE_PATH': 'config/config.yaml'})

    api_app = ProspectorService(cfg)
    gunicorn_app = GunicornApp(api_app, cfg.gunicorn)
    gunicorn_app.run()
Exemple #6
0
def main():
    docopt(__doc__)

    cfg = aumbry.load(aumbry.FILE, AppConfig,
                      {'CONFIG_FILE_PATH': './etc/example/config.yml'})

    api_app = MyService(cfg)
    gunicorn_app = GunicornApp(api_app, cfg.gunicorn)

    gunicorn_app.run()
Exemple #7
0
def main():
    # docopt(__doc__)

    cfg = aumbry.load(aumbry.FILE, AppConfig,
                      {"CONFIG_FILE_PATH": "./etc/analyst/config.yml"})

    api_app = AnalystService(cfg)
    gunicorn_app = GunicornApp(api_app, cfg.gunicorn)

    gunicorn_app.run()
Exemple #8
0
    def can_save(self, raw, cls):
        cfg = cls()
        cfg.nope = 'testing'

        with tempfile.NamedTemporaryFile() as temp:
            options = {'CONFIG_FILE_PATH': temp.name}
            aumbry.save(aumbry.FILE, cfg, options)

            # Load up the saved file
            loaded_cfg = aumbry.load(aumbry.FILE, cls, options)
            expect(loaded_cfg.nope).to.equal(cfg.nope)
Exemple #9
0
    def setting_a_valid_path(self):
        search_paths = py.get_module_by_name('aumbry.sources').__path__

        temp, options = write_temp_file(raw_yaml)

        cfg = aumbry.load('file',
                          SampleYamlConfig,
                          options,
                          search_paths=search_paths)
        os.remove(temp.name)

        expect(cfg.nope).to.equal('testing')
Exemple #10
0
    def setUp(self):
        super(AppTestCase, self).setUp()
        # Assume the hypothetical `myapp` package has a
        # function called `create()` to initialize and
        # return a `backend.API` instance.
        # self.app = myapp.create()
        # self.mysqld = self.Mysqld()

        cfg = aumbry.load(aumbry.FILE, AppConfig,
                          {'CONFIG_FILE_PATH': './etc/config.yml'})
        self.app = AlterService(cfg)
        self.api_version = cfg.api_version
        self.prefix = 'api'
Exemple #11
0
    def can_successfully_load_from_consul(self):
        with requests_mock.Mocker() as mock:
            value = base64.b64encode(raw_yaml.encode('utf-8'))
            resp = [{'Value': value.decode('utf-8')}]
            mock.get('http://bam/v1/kv/test_key', text=json.dumps(resp))

            options = {
                'CONSUL_URI': 'http://bam',
                'CONSUL_KEY': 'test_key',
            }

            cfg = aumbry.load(aumbry.CONSUL, SampleYamlConfig, options)
            expect(cfg.nope).to.equal('testing')
Exemple #12
0
    def can_save_and_load(self):
        cfg = SampleYamlConfig()
        cfg.nope = 'testing'

        with tempfile.NamedTemporaryFile() as temp:
            options = {
                'CONFIG_FILE_PATH': temp.name,
                'CONFIG_FILE_FERNET_KEY': Fernet.generate_key().decode('utf-8')
            }
            aumbry.save(aumbry.FERNET, cfg, options)

            # Load up the saved file
            loaded_cfg = aumbry.load(aumbry.FERNET, SampleYamlConfig, options)
            expect(loaded_cfg.nope).to.equal(cfg.nope)
Exemple #13
0
    def can_successfully_load_yaml_from_etcd(self):
        with requests_mock.Mocker() as mock:
            value = base64.b64encode(raw_yaml.encode('utf-8'))
            resp = {
                'node': {
                    'value': value.decode('utf-8'),
                },
            }
            mock.get('http://bam/v2/keys/test_key', text=json.dumps(resp))

            options = {
                'ETCD2_URI': 'http://bam',
                'ETCD2_KEY': 'test_key',
            }

            cfg = aumbry.load(aumbry.ETCD2, SampleYamlConfig, options)
            expect(cfg.nope).to.equal('testing')
Exemple #14
0
def main():
    logging.basicConfig()

    cfg = aumbry.load(aumbry.FILE, AppConfig)

    logging.getLogger(__name__).level = parse_log_level(cfg.log_level)
    logger = logging.getLogger(__name__)

    logger.info('Using bayeslite version: {}'.format(bayeslite.__version__))

    bdb = get_bdb(cfg, logger)

    fips_cols = find_fips_cols(cfg, bdb, 'resources/national_county.txt')
    logger.info("Found fips columns: {}".format(fips_cols))

    api_def = read_api('api.yaml')

    gunicorn_app = GunicornApp(cfg, bdb, api_def, fips_cols, logger)

    gunicorn_app.run()
Exemple #15
0
    def can_use_preprocessors(self, raw, cls):
        cfg = cls()
        cfg.nope = 'testing'

        with tempfile.NamedTemporaryFile() as temp:
            options = {'CONFIG_FILE_PATH': temp.name}
            aumbry.save(aumbry.FILE,
                        cfg,
                        options,
                        preprocessor=lambda data: base64.b64encode(data))

            expect('testing').not_to.be_in(temp.file.read().decode('utf-8'))

            # Load up the saved file
            loaded_cfg = aumbry.load(
                aumbry.FILE,
                cls,
                options,
                preprocessor=lambda data: base64.b64decode(data))
            expect(loaded_cfg.nope).to.equal(cfg.nope)
def main():
    docopt(__doc__)

    cfg = aumbry.load(
        aumbry.FILE,
        AppConfig,
        {
            'CONFIG_FILE_PATH': './src/config/config.yml'
        }
    )

    # Create an instance of the service and serve it
    api_app = BimbangalService(cfg)

    # Check platform whether to run using waitress or gunicorn
    if platform.system() == 'Windows':
        from waitress import serve
        connect(host=cfg.db['conn'])
        serve(api_app, host=cfg.waitress['host'], port=cfg.waitress['port'])
    else:
        from .gunicorn_worker import GunicornApp
        gunicorn_app = GunicornApp(api_app, cfg.gunicorn)
        gunicorn_app.run()
Exemple #17
0
    def can_successfully_save_and_load(self):
        with mock_ssm():
            options = {
                'PARAMETER_STORE_AWS_REGION': 'us-west-2',
                'PARAMETER_STORE_PREFIX': '/aumbry-test',
            }
            expected_cfg = SampleGenericConfig()
            expected_cfg.nope = 'testing'
            expected_cfg.sample_list = ['trace']
            expected_cfg.sample_dict = {'trace': 'boom'}
            expected_cfg.sample_model = SampleJsonConfig()
            expected_cfg.sample_model.nope = 'testing2'

            # Save Sample Config
            aumbry.save(aumbry.PARAM_STORE, expected_cfg, options)

            # Retrieve back the config
            cfg = aumbry.load(aumbry.PARAM_STORE, SampleGenericConfig, options)

        expect(cfg.nope).to.equal(expected_cfg.nope)
        expect(cfg.sample_dict).to.equal({'trace': 'boom'})
        expect(cfg.sample_list).to.equal(expected_cfg.sample_list)
        expect(cfg.sample_model.nope).to.equal(expected_cfg.sample_model.nope)
def load_config_file():
    return aumbry.load(aumbry.FILE, AppConfig,
                       {"CONFIG_FILE_PATH": "./config.json"})
Exemple #19
0
class CustomWorker(SyncWorker):
    def handle_quit(self, sig, frame):
        self.app.application.stop(sig)
        super().handle_quit(sig, frame)

    def run(self):
        self.app.application.start()
        super().run()


class GunicornApplication(BaseApplication):
    def __init__(self, app, options=None):
        self.options = options or {}
        self.application = app
        super().__init__()

    def load_config(self):
        for key, value in self.options.items():
            self.cfg.set(key.lower(), value)

    def load(self):
        return self.application


cfg = aumbry.load(aumbry.FILE, PotionConfig,
                  {'CONFIG_FILE_PATH': './config/config.yml'})

app = PotionApplication(cfg)
guinicorn_app = GunicornApplication(app, cfg.gunicorn)
guinicorn_app.run()
Exemple #20
0
import requests
import time
from datetime import datetime
from prospector.db.models import IPAddress, Person, Address, ZipCode
from prospector.db.manager import DBManager
import GeoIP
import reverse_geocoder as rg
from celery.schedules import crontab
from celery.utils.log import get_task_logger
from prospector.config import AppConfig
from sqlalchemy import exc
from random import randint
from bs4 import BeautifulSoup

# database config
cfg = aumbry.load(aumbry.FILE, AppConfig,
                  {'CONFIG_FILE_PATH': '../config/config.yaml'})
mgr = DBManager(cfg.db.connection)

app = celery.Celery('tasks',
                    broker='amqp://',
                    backend='redis://localhost:6379/0')

# logger
logger = get_task_logger(__name__)

# open the geo data file once and store it in cache memory
gi = GeoIP.open('/var/lib/geoip/GeoLiteCity.dat',
                GeoIP.GEOIP_INDEX_CACHE | GeoIP.GEOIP_CHECK_CACHE)

# celery beat
app.conf.beat_schedule = {
Exemple #21
0
    @static_folder.getter
    def static_folder(self):
        return getattr(self, '_static_folder', '')


class ServerConfig(YamlConfig):
    __mapping__ = {
        'db': Attr('db', DatabaseConfig),
        'app': Attr('app', AppConfig),
    }

    def __init__(self):
        self.db = DatabaseConfig()
        self.app = AppConfig()


cfg = aumbry.load(aumbry.FILE, ServerConfig, {
    'CONFIG_FILE_PATH':
    os.path.join(os.path.abspath(os.getcwd()), 'config.yml')
})

log = logging.getLogger('app')
log.setLevel(cfg.app.logger.level)
f = logging.Formatter(cfg.app.logger.format, datefmt='%d-%m-%Y %H:%M:%S')
ch = logging.StreamHandler()
ch.setFormatter(f)
log.addHandler(ch)
if cfg.app.logger.is_log_file:
    cf = logging.FileHandler(filename=cfg.app.logger.file)
    cf.setFormatter(f)
    log.addHandler(cf)
Exemple #22
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import aumbry


class UserConfig(aumbry.JsonConfig):
    __mapping__ = {"uuid": ["uuid", str]}


class ServerConfig(aumbry.JsonConfig):
    __mapping__ = {"master": ["master", str], "slave": ["slave", str]}


class RpcConfig(aumbry.JsonConfig):
    __mapping__ = {
        "version": ["version", int],
        "user": ["user", UserConfig],
        "server": ["server", ServerConfig],
        "port": ["port", int],
        "auth_ips": ["auth_ips", list]
    }


_options = {
    'CONFIG_FILE_PATH': './.secret.json',
}

CONFIG = aumbry.load(aumbry.FILE, RpcConfig, _options)
# print("load app config, version: %s " % CONFIG.version)
Exemple #23
0
import falcon
import aumbry

from sensat.resources import ReadingsResource
from sensat.db.connection import DatabaseConnection
from sensat.config import AppConfig
from sensat.constants import CONFIG_FILE_PATH

application = falcon.API()

config = aumbry.load(aumbry.FILE, AppConfig,
                     {'CONFIG_FILE_PATH': CONFIG_FILE_PATH})

dbConnection = DatabaseConnection(config.db)

readingsResource = ReadingsResource(dbConnection)
application.add_route('/readings/{boxId}/{fromDate}/{toDate}',
                      readingsResource)
Exemple #24
0
            RequireJSON(),
            SQLAlchemySessionManager(self.mgr.DBSession),
            Auth(cfg),
        ])

    def start(self):
        self.mgr.setup()
        api_kiosk = KioskAPI(cfg)
        api_dc = DcAPI(cfg)
        api_user = UserAPI(cfg)
        api_cashier = CashierAPI(cfg)
        self.add_route('/kiosk/{method}', api_kiosk)
        self.add_route('/dc/{method}', api_dc)
        self.add_route('/user/{method}', api_user)
        self.add_route('/cashier/{method}', api_cashier)
        self.add_sink(handle404, '')
        pass

    def stop(self, signal):
        pass


cfg = aumbry.load(
    aumbry.FILE, AppConfig, {
        'CONFIG_FILE_PATH':
        os.path.dirname(os.path.realpath(__file__)) + '/../config/config.yml'
    })

api_app = CoinpayAPI(cfg)
api_app.start()
Exemple #25
0
Example Application

Usage:
    backend-aness [options]

Options:
    -h --help                   Show this screen.
"""
import aumbry
from docopt import docopt
from wsgiref import simple_server

from aness.app import AlterService
from aness.config import AppConfig

docopt(__doc__)

cfg = aumbry.load(
    aumbry.FILE,
    AppConfig,
    {
        'CONFIG_FILE_PATH': './etc/config.yml'
    }
)

app = application = AlterService(cfg)

if __name__ == '__main__':
    httpd = simple_server.make_server('127.0.0.1', 8001, app)
    httpd.serve_forever()
Exemple #26
0
def config():
    return aumbry.load(aumbry.FILE, AppConfig,
                       {'CONFIG_FILE_PATH': './etc/config.yml'})