Exemplo n.º 1
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
Exemplo n.º 2
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
Exemplo n.º 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
Exemplo n.º 4
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
Exemplo n.º 5
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
Exemplo n.º 6
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:
Exemplo n.º 7
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)
Exemplo n.º 8
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)
Exemplo n.º 9
0
 def test_connect_to_region(self):
     """ Can connect to a dynamo region """
     conn = DynamoDBConnection.connect('us-west-1')
     self.assertIsNotNone(conn.host)
Exemplo n.º 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()
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 13
0
 def test_connect_to_region(self):
     """ Can connect to a dynamo region """
     conn = DynamoDBConnection.connect('us-west-1')
     self.assertIsNotNone(conn.host)
Exemplo n.º 14
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()
Exemplo n.º 15
0
 def connect(self, *args, **kwargs):
     """ Connect to a specific host """
     self.dynamo = DynamoDBConnection.connect(*args, **kwargs)
Exemplo n.º 16
0
 def connect_to_region(self, region, **kwargs):
     """ Connect to an AWS region """
     self.dynamo = DynamoDBConnection.connect(region, **kwargs)
Exemplo n.º 17
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()
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)