Example #1
0
def generate_cf_dynamo_schema(target):
    dynamo_connection = DynamoDBConnection()

    class FakeClient(object):
        def create_table(self, *args, **kwargs):
            write_schema_to_yaml(target, **kwargs)
            return {}

    client = FakeClient()
    dynamo_connection.client = client

    class FakeDynamo(object):
        def list_tables(self):
            return []

        def create_table(self, *args):
            result = dynamo_connection.create_table(*args)

        def describe_table(self, *args):
            StatusStruct = namedtuple('Status', 'status')
            return StatusStruct(status='ACTIVE')

    dynamo = FakeDynamo()
    engine = Engine()
    engine.dynamo = dynamo

    sys.path = ['{}/app/models'.format(target)] + sys.path
    modelModules = glob.glob('{}/app/models'.format(target) + '/*.py')
    models = [basename(f)[:-3] for f in modelModules if isfile(f)]
    for modelName in models:
        if modelName != '__init__':
            engine.register(getattr(importlib.__import__(modelName),
                                    modelName))

    engine.create_schema()
Example #2
0
File: cli.py Project: cce/dql
    def initialize(self, region='us-west-1', host='localhost', port=8000,
                   access_key=None, secret_key=None, config_dir=None):
        """ Set up the repl for execution. """
        # Tab-complete names with a '-' in them
        import readline
        delims = set(readline.get_completer_delims())
        if '-' in delims:
            delims.remove('-')
            readline.set_completer_delims(''.join(delims))

        self._conf_dir = (config_dir or
                          os.path.join(os.environ.get('HOME', '.'), '.config'))
        self.session = botocore.session.get_session()
        if access_key:
            self.session.set_credentials(access_key, secret_key)
        if region == 'local':
            conn = DynamoDBConnection.connect_to_host(host, port,
                                                      session=self.session)
        else:
            conn = DynamoDBConnection.connect_to_region(region, self.session)
        self.engine = FragmentEngine(conn)

        conf = self.load_config()
        display_name = conf.get('display')
        if display_name is not None:
            self.display = DISPLAYS[display_name]
        else:
            self.display = get_default_display()
        self.formatter = SmartFormat(pagesize=conf.get('pagesize', 1000),
                                     width=conf.get('width', 80))
        for line in conf.get('autorun', []):
            six.exec_(line, self.engine.scope)
Example #3
0
    def configure(cls, settings):
        kwargs = super(DynamoCache, cls).configure(settings)

        access_key = settings.get('db.aws_access_key_id')
        secret_key = settings.get('db.aws_secret_access_key')
        region = settings.get('db.region_name')
        host = settings.get('db.host')
        port = int(settings.get('db.port', 8000))
        secure = asbool(settings.get('db.secure', False))
        namespace = settings.get('db.namespace', ())
        graceful_reload = asbool(settings.get('db.graceful_reload', False))

        if host is not None:
            connection = DynamoDBConnection.connect(region,
                                                    host=host,
                                                    port=port,
                                                    is_secure=secure,
                                                    access_key=access_key,
                                                    secret_key=secret_key)
        elif region is not None:
            connection = DynamoDBConnection.connect(region,
                                                    access_key=access_key,
                                                    secret_key=secret_key)
        else:
            raise ValueError("Must specify either db.region_name or db.host!")
        kwargs['engine'] = engine = Engine(namespace=namespace,
                                           dynamo=connection)
        kwargs['graceful_reload'] = graceful_reload

        engine.register(DynamoPackage, PackageSummary)
        LOG.info("Checking if DynamoDB tables exist")
        engine.create_schema()
        return kwargs
Example #4
0
    def configure(cls, settings):
        kwargs = super(DynamoCache, cls).configure(settings)

        access_key = settings.get('db.access_key')
        secret_key = settings.get('db.secret_key')
        region = settings.get('db.region')
        host = settings.get('db.host')
        port = int(settings.get('db.port', 8000))
        secure = asbool(settings.get('db.secure', False))
        namespace = settings.get('db.namespace', ())

        if region is not None:
            connection = DynamoDBConnection.connect(region,
                                                    access_key=access_key,
                                                    secret_key=secret_key)
        elif host is not None:
            connection = DynamoDBConnection.connect('us-east-1',
                                                    host=host,
                                                    port=port,
                                                    is_secure=secure,
                                                    access_key=access_key,
                                                    secret_key=secret_key)
        else:
            raise ValueError("Must specify either db.region or db.host!")
        kwargs['engine'] = engine = Engine(namespace=namespace,
                                           dynamo=connection)

        engine.register(DynamoPackage, PackageSummary)
        engine.create_schema()
        return kwargs
Example #5
0
    def configure(cls, settings):
        kwargs = super(DynamoCache, cls).configure(settings)

        access_key = settings.get('db.access_key')
        secret_key = settings.get('db.secret_key')
        region = settings.get('db.region')
        host = settings.get('db.host')
        port = int(settings.get('db.port', 8000))
        secure = asbool(settings.get('db.secure', False))
        namespace = settings.get('db.namespace', ())

        if region is not None:
            connection = DynamoDBConnection.connect(region,
                                                    access_key=access_key,
                                                    secret_key=secret_key)
        elif host is not None:
            connection = DynamoDBConnection.connect('us-east-1',
                                                    host=host,
                                                    port=port,
                                                    is_secure=secure,
                                                    access_key=access_key,
                                                    secret_key=secret_key)
        else:
            raise ValueError("Must specify either db.region or db.host!")
        kwargs['engine'] = engine = Engine(namespace=namespace,
                                           dynamo=connection)

        engine.register(DynamoPackage, PackageSummary)
        engine.create_schema()
        return kwargs
Example #6
0
 def connection(self, connection: DynamoDBConnection) -> None:
     """Change the dynamo connection"""
     if connection is not None:
         connection.subscribe("capacity", self._on_capacity_data)
         connection.default_return_capacity = True
     if self._connection is not None:
         connection.unsubscribe("capacity", self._on_capacity_data)
     self._connection = connection
     self._cloudwatch_connection = None
     self.cached_descriptions = {}
Example #7
0
File: cli.py Project: cce/dql
    def do_use(self, region, host='localhost', port=8000):
        """
        Switch the AWS region

        You may also specify 'use local host=localhost port=8000' to use the
        DynamoDB Local service

        """
        if region == 'local':
            conn = DynamoDBConnection.connect_to_host(
                host, port, session=self.session)
        else:
            conn = DynamoDBConnection.connect_to_region(region, self.session)
        self.engine.connection = conn
Example #8
0
    def configure(cls, settings):
        kwargs = super(DynamoCache, cls).configure(settings)

        access_key = settings.get("db.aws_access_key_id")
        secret_key = settings.get("db.aws_secret_access_key")
        region = settings.get("db.region_name")
        host = settings.get("db.host")
        port = int(settings.get("db.port", 8000))
        secure = asbool(settings.get("db.secure", False))
        namespace = settings.get("db.namespace", ())
        graceful_reload = asbool(settings.get("db.graceful_reload", False))

        tablenames = aslist(settings.get("db.tablenames", []))
        if tablenames:
            if len(tablenames) != 2:
                raise ValueError("db.tablenames must be a 2-element list")
            DynamoPackage.meta_.name = tablenames[0]
            PackageSummary.meta_.name = tablenames[1]

        if host is not None:
            connection = DynamoDBConnection.connect(
                region,
                host=host,
                port=port,
                is_secure=secure,
                access_key=access_key,
                secret_key=secret_key,
            )
        elif region is not None:
            connection = DynamoDBConnection.connect(region,
                                                    access_key=access_key,
                                                    secret_key=secret_key)
        else:
            raise ValueError("Must specify either db.region_name or db.host!")
        kwargs["engine"] = engine = Engine(namespace=namespace,
                                           dynamo=connection)
        kwargs["graceful_reload"] = graceful_reload

        engine.register(DynamoPackage, PackageSummary)
        LOG.info("Checking if DynamoDB tables exist")
        engine.create_schema()
        return kwargs
Example #9
0
    def configure(cls, settings):
        kwargs = super(DynamoCache, cls).configure(settings)

        access_key = settings.get("db.aws_access_key_id")
        secret_key = settings.get("db.aws_secret_access_key")
        region = settings.get("db.region_name")
        host = settings.get("db.host")
        port = int(settings.get("db.port", 8000))
        secure = asbool(settings.get("db.secure", False))
        namespace = settings.get("db.namespace", ())
        graceful_reload = asbool(settings.get("db.graceful_reload", False))

        tablenames = aslist(settings.get("db.tablenames", []))
        if tablenames:
            if len(tablenames) != 2:
                raise ValueError("db.tablenames must be a 2-element list")
            DynamoPackage.meta_.name = tablenames[0]
            PackageSummary.meta_.name = tablenames[1]

        if host is not None:
            connection = DynamoDBConnection.connect(
                region,
                host=host,
                port=port,
                is_secure=secure,
                access_key=access_key,
                secret_key=secret_key,
            )
        elif region is not None:
            connection = DynamoDBConnection.connect(
                region, access_key=access_key, secret_key=secret_key
            )
        else:
            raise ValueError("Must specify either db.region_name or db.host!")
        kwargs["engine"] = engine = Engine(namespace=namespace, dynamo=connection)
        kwargs["graceful_reload"] = graceful_reload

        engine.register(DynamoPackage, PackageSummary)
        LOG.info("Checking if DynamoDB tables exist")
        engine.create_schema()
        return kwargs
Example #10
0
 def connect(self, *args, **kwargs):
     """ Proxy to DynamoDBConnection.connect. """
     self.connection = DynamoDBConnection.connect(*args, **kwargs)
     self._session = kwargs.get("session")
     if self._session is None:
         self._session = botocore.session.get_session()
Example #11
0
 def test_connect_to_host_without_session(self):
     """ Can connect to a dynamo host without passing in a session """
     conn = DynamoDBConnection.connect('us-west-1', host='localhost')
     self.assertIsNotNone(conn.host)
Example #12
0
 def test_connect_to_region_creds(self):
     """ Can connect to a dynamo region with credentials """
     conn = DynamoDBConnection.connect(
         'us-west-1', access_key='abc', secret_key='12345')
     self.assertIsNotNone(conn.host)
Example #13
0
 def test_connect_to_region(self):
     """ Can connect to a dynamo region """
     conn = DynamoDBConnection.connect('us-west-1')
     self.assertIsNotNone(conn.host)
Example #14
0
 def test_connect_to_host_without_session_old(self):
     """ Can connect to a dynamo host without passing in a session """
     conn = DynamoDBConnection.connect_to_host(access_key='abc',
                                               secret_key='12345')
     self.assertIsNotNone(conn.host)
Example #15
0
def main(pargs):
    global redis
    if pargs.production:
        serverConf = configobj.ConfigObj('production.ini')
    else:
        serverConf = configobj.ConfigObj('develop.ini')

    routes = [
        (r"/auth/login", FacebookGraphLoginHandler),
        (r"/", HomeHandler),
        (r"/referral/([^/]+)", ReferralHandler),
        (r"/r/([^/]+)", ReferralHandler),
        (r'/(favicon.ico)', StaticFileHandler, {
            "path": "./static/"
        }),
    ]

    for api in [game, tips, user, referral, prizes]:
        routes.extend(get_routes(api))

    if pargs.admin:
        routes.extend(get_routes(admin))
        routes.extend(get_routes(box))
        from encontact import UserDataHandler
        routes.extend([
            (r"/admin/encontact?/", UserDataHandler),
        ])

    pprint(routes, indent=4)

    mailer = Mail(aws_access_key_id=serverConf['ses']['acceskeyid'],
                  aws_secret_access_key=serverConf['ses']['secretacceskeyid'],
                  region=serverConf['ses']['region'],
                  sender=serverConf['ses']['sender'],
                  template=serverConf['ses']['templates'])

    if pargs.production:
        dyn = DynamoDBConnection.connect(
            region=serverConf['dynamo']['region'],
            access_key=serverConf['dynamo']['acceskeyid'],
            secret_key=serverConf['dynamo']['secretacceskeyid'])
        session_settings = dict(
            driver="redis",
            force_persistence=True,
            cache_driver=True,
            driver_settings=dict(
                host=serverConf['redis']['host'],
                port=int(serverConf['redis']['port']),
                db=int(serverConf['redis']['db']),
                max_connections=1024,
            ),
        )
        pool = ConnectionPool(max_connections=2,
                              host=serverConf['redis']['host'],
                              port=int(serverConf['redis']['port']),
                              db=int(serverConf['redis']['db']) + 1)

        pool2 = ConnectionPool(max_connections=2,
                               host=serverConf['redis']['host'],
                               port=int(serverConf['redis']['port']),
                               db=int(serverConf['redis']['db']))

    else:
        dyn = DynamoDBConnection.connect(region='sp-east',
                                         host='127.0.0.1',
                                         port=8000,
                                         is_secure=False,
                                         access_key='asdas',
                                         secret_key='123ads')
        session_settings = dict(
            driver="redis",
            force_persistence=True,
            cache_driver=True,
            driver_settings=dict(
                host='localhost',
                port=6379,
                db=0,
                max_connections=1024,
            ),
        )
        pool = ConnectionPool(max_connections=2,
                              host='localhost',
                              port=6379,
                              db=1)

        pool2 = ConnectionPool(max_connections=2,
                               host='localhost',
                               port=6379,
                               db=0)

    redis = Redis(connection_pool=pool)
    redis2 = Redis(connection_pool=pool2)
    engine = Engine(dynamo=dyn)
    log = logging.getLogger(__name__)
    a = logging.basicConfig(
        level=logging.INFO,
        format=
        '[ %(asctime)s ][ %(levelname)s ][ %(filename)20s:%(lineno)4s - %(funcName)20s() ] %(message)s',
        datefmt='%m-%d %H:%M',
        filename='log/nextgame.log',
        filemode='a')

    log.addHandler(a)
    settings = {
        "debug": False,
        'xsrf_cookies': False,
        'serverConfig': serverConf,
        'instance': serverConf.get('instance'),
        'engine': engine,
        'facebook_api_key': serverConf['facebook']['key'],
        'facebook_secret': serverConf['facebook']['secret'],
        'session': session_settings,
        'template_path': serverConf['ses']['templates'],
        "login_url": "/auth/login/",
        "cookie_secret": 'sopadeletrinhas123',
        "mailer": mailer,
        "production": False
    }

    if (pargs.debug):
        # log.setLevel(logging.DEBUG)
        log.debug('DEBUGGING LOG')
        settings['debug'] = True

    app = Application(routes=routes,
                      settings=settings,
                      db_conn={
                          'ping': redis,
                          'session': redis2
                      })

    if pargs.provision:
        game.models.create_schemas(engine)
        tips.models.create_schemas(engine)
        referral.models.create_schemas(engine)

    if (pargs.production):
        print('Server Production Starting')
        server = tornado.httpserver.HTTPServer(app)
        server.bind(serverConf['tornado']['port'])
        server.start(int(serverConf['tornado']['instances']))
        tornado.ioloop.IOLoop.configure(TornadoUvloop)

    else:
        print('Server Develop Starting')
        app.listen(serverConf['tornado']['port'])
        tornado.ioloop.IOLoop.configure(TornadoUvloop)

    tornado.ioloop.IOLoop.current().start()
from dynamo3 import DynamoDBConnection
from flywheel import Engine
from auth.auth_main import *

connection = DynamoDBConnection.connect(region=DynamoAuth.region,
                                        access_key=DynamoAuth.access_key,
                                        secret_key=DynamoAuth.secret_key,
                                        host="localhost",
                                        port=8000,
                                        is_secure=False)

engine = Engine(connection)
Example #17
0
 def test_connect_to_region_creds(self):
     """ Can connect to a dynamo region with credentials """
     conn = DynamoDBConnection.connect('us-west-1',
                                       access_key='abc',
                                       secret_key='12345')
     self.assertIsNotNone(conn.host)
Example #18
0
 def test_connect_to_host_without_session_old(self):
     """ Can connect to a dynamo host without passing in a session """
     conn = DynamoDBConnection.connect_to_host(access_key='abc',
                                               secret_key='12345')
     self.assertIsNotNone(conn.host)
Example #19
0
File: engine.py Project: cce/dql
 def connect_to_region(self, region, *args, **kwargs):
     """ Connect the engine to an AWS region """
     self.connection = DynamoDBConnection.connect_to_region(region, *args,
                                                            **kwargs)
Example #20
0
File: engine.py Project: cce/dql
 def connect_to_host(self, *args, **kwargs):
     """ Connect the engine to a specific host """
     self.connection = DynamoDBConnection.connect_to_host(*args, **kwargs)
Example #21
0
 def test_connect_to_region(self):
     """ Can connect to a dynamo region """
     conn = DynamoDBConnection.connect('us-west-1')
     self.assertIsNotNone(conn.host)
Example #22
0
 def connect(self, *args, **kwargs):
     """ Proxy to DynamoDBConnection.connect. """
     self.connection = DynamoDBConnection.connect(*args, **kwargs)
     self._session = kwargs.get("session")
     if self._session is None:
         self._session = botocore.session.get_session()
Example #23
0
 def test_connect_to_host_without_session(self):
     """ Can connect to a dynamo host without passing in a session """
     conn = DynamoDBConnection.connect('us-west-1', host='localhost')
     self.assertIsNotNone(conn.host)
Example #24
0
 def connect_to_region(self, region, **kwargs):
     """ Connect to an AWS region """
     self.dynamo = DynamoDBConnection.connect(region, **kwargs)
Example #25
0
    firstAccess = Field(data_type=int, default=1)
    created_at = Field(data_type=datetime.datetime)
    updated_at = Field(data_type=datetime.datetime, nullable=True)
    deleted_at = Field(data_type=datetime.datetime,
                       nullable=True,
                       index='create-index')
    referral = Field(data_type=str, default='')
    avatar = Field(data_type=dict, nullable=True)
    win = Field(data_type=dict, nullable=True)
    win_email = Field(data_type=list, nullable=True)
    is_dirty = Field(data_type=bool, default=False)
    is_admin = Field(data_type=int, default=0, index='admin-index')


dyn = DynamoDBConnection.connect(region=FLYWHEEL_REGION,
                                 access_key=AWS_ACCESS_KEY,
                                 secret_key=AWS_SECRET_ACCESS_KEY)
db = Engine(dynamo=dyn)

cont = {
    'easy': [],
    'medium': [],
    'hard': [],
    'impossible': [],
}

if __name__ == '__main__':
    context = db.scan(User).filter(User.mobile != None).gen()
    print("DONE SCAN")
    for u in context:
        try:
Example #26
0
 def connect(self, *args, **kwargs):
     """ Connect to a specific host """
     self.dynamo = DynamoDBConnection.connect(*args, **kwargs)