Exemplo n.º 1
0
 def setup(self):
     if not self.db.about(ABOUT_TABLE):
         with self.db.transaction() as t:
             t.execute(
                 sql_create(ABOUT_TABLE, {"version": "TEXT", "next_id": "INTEGER"})
             )
             t.execute(sql_insert(ABOUT_TABLE, {"version": "1.0", "next_id": 1000}))
             t.execute(sql_create(DIGITS_TABLE, {"value": "INTEGER"}))
             t.execute(sql_insert(DIGITS_TABLE, [{"value": i} for i in range(10)]))
Exemplo n.º 2
0
    def get_or_create_facts(self, fact_name, uid=UID):
        """
        FIND TABLE BY NAME, OR CREATE IT IF IT DOES NOT EXIST
        :param fact_name:  NAME FOR THE CENTRAL INDEX
        :param uid: name, or list of names, for the GUID
        :return: Facts
        """
        about = self.db.about(fact_name)
        if not about:
            if uid != UID:
                Log.error("do not know how to handle yet")

            self.ns.columns._snowflakes[fact_name] = ["."]
            self.ns.columns.add(Column(
                name="_id",
                es_column="_id",
                es_index=fact_name,
                es_type=json_type_to_sqlite_type[STRING],
                jx_type=STRING,
                nested_path=['.'],
                multi=1,
                last_updated=Date.now()
            ))
            command = sql_create(fact_name, {UID: "INTEGER PRIMARY KEY", GUID: "TEXT"}, unique=UID)

            with self.db.transaction() as t:
                t.execute(command)

        return QueryTable(fact_name, self)
Exemplo n.º 3
0
    def __init__(self,
                 flask_app,
                 auth0,
                 permissions,
                 session_manager,
                 device=None):
        if not auth0.domain:
            Log.error("expecting auth0 configuration")

        self.auth0 = auth0
        self.permissions = permissions
        self.session_manager = session_manager

        # ATTACH ENDPOINTS TO FLASK APP
        endpoints = auth0.endpoints
        if not endpoints.login or not endpoints.logout or not endpoints.keep_alive:
            Log.error("Expecting paths for login, logout and keep_alive")

        add_flask_rule(flask_app, endpoints.login, self.login)
        add_flask_rule(flask_app, endpoints.logout, self.logout)
        add_flask_rule(flask_app, endpoints.keep_alive, self.keep_alive)

        if device:
            self.device = device
            db = self.device.db = Sqlite(device.db)
            if not db.about("device"):
                with db.transaction() as t:
                    t.execute(
                        sql_create(
                            "device",
                            {
                                "state": "TEXT PRIMARY KEY",
                                "session_id": "TEXT"
                            },
                        ))
            if device.auth0.redirect_uri != text(
                    URL(device.home, path=device.endpoints.callback)):
                Log.error(
                    "expecting home+endpoints.callback == auth0.redirect_uri")

            add_flask_rule(flask_app, device.endpoints.register,
                           self.device_register)
            add_flask_rule(flask_app, device.endpoints.status,
                           self.device_status)
            add_flask_rule(flask_app, device.endpoints.login,
                           self.device_login)
            add_flask_rule(flask_app, device.endpoints.callback,
                           self.device_callback)
Exemplo n.º 4
0
    def create_or_replace_facts(self, fact_name, uid=UID):
        """
        MAKE NEW TABLE, REPLACE OLD ONE IF EXISTS
        :param fact_name:  NAME FOR THE CENTRAL INDEX
        :param uid: name, or list of names, for the GUID
        :return: Facts
        """
        self.remove_facts(fact_name)
        self.ns.columns._snowflakes[fact_name] = ["."]

        if uid != UID:
            Log.error("do not know how to handle yet")

        command = sql_create(fact_name, {UID: "INTEGER PRIMARY KEY", GUID: "TEXT"}, unique=UID)

        with self.db.transaction() as t:
            t.execute(command)

        snowflake = Snowflake(fact_name, self.ns)
        return Facts(self, snowflake)
Exemplo n.º 5
0
def setup(broker):
    version_table(db=broker.db, version_table=VERSION_TABLE)

    with broker.db.transaction() as t:
        t.execute(
            sql_create(
                table=QUEUE,
                properties={
                    "id": "INTEGER PRIMARY KEY NOT NULL",
                    "name": "TEXT NOT NULL",
                    "next_serial": "LONG NOT NULL",
                    "block_size_mb": "LONG NOT NULL",
                    "block_start": "LONG NOT NULL",
                    "block_end": "LONG NOT NULL"
                },
                unique="name",
            ))

        t.execute(
            sql_create(
                table=BLOCKS,
                properties={
                    "queue": "INTEGER NOT NULL",
                    "serial": "LONG NOT NULL",
                    "path": "TEXT NOT NULL",
                    "last_used": "DOUBLE NOT NULL",
                },
                primary_key=("queue", "serial"),
                foreign_key={"queue": {
                    "table": QUEUE,
                    "column": "id"
                }},
            ))

        t.execute(
            sql_create(
                table=SUBSCRIBER,
                properties={
                    "id": "INTEGER PRIMARY KEY NOT NULL",
                    "queue": "INTEGER NOT NULL",
                    "confirm_delay_seconds": "LONG NOT NULL",
                    "look_ahead_serial": "LONG NOT NULL",
                    "last_confirmed_serial": "LONG NOT NULL",
                    "next_emit_serial": "LONG NOT NULL",
                    "last_emit_timestamp": "DOUBLE NOT NULL",
                },
                foreign_key={"queue": {
                    "table": QUEUE,
                    "column": "id"
                }},
            ))

        t.execute(
            sql_create(
                table=MESSAGES,
                properties={
                    "queue": "INTEGER NOT NULL",
                    "serial": "LONG NOT NULL",
                    "content": "TEXT",
                },
                primary_key=("queue", "serial"),
                foreign_key={"queue": {
                    "table": QUEUE,
                    "column": "id"
                }},
            ))

        t.execute(
            sql_create(
                table=UNCONFIRMED,
                properties={
                    "subscriber": "LONG NOT NULL",
                    "serial": "LONG NOT NULL",
                    "deliver_time": "DOUBLE NOT NULL",
                },
                foreign_key={
                    "subscriber": {
                        "table": SUBSCRIBER,
                        "column": "id"
                    },
                    "serial": {
                        "table": MESSAGES,
                        "column": "id"
                    },
                },
            ))