Ejemplo n.º 1
0
def make_rest_app(
        db_filepath: Path,
        this_node,
        log: Logger = Logger("http-application-layer")
        ) -> Tuple[Flask, Datastore]:
    """
    Creates a REST application and an associated ``Datastore`` object.
    Note that the REST app **does not** hold a reference to the datastore;
    it is your responsibility to ensure it lives for as long as the app does.
    """

    # A trampoline function for the real REST app,
    # to ensure that a reference to the node and the datastore object is not held by the app closure.
    # One would think that it's enough to only remove a reference to the node,
    # but `rest_app` somehow holds a reference to itself, Uroboros-like,
    # and will hold the datastore reference if it is created there.

    log.info("Starting datastore {}".format(db_filepath))
    datastore = Datastore(db_filepath)
    rest_app = _make_rest_app(weakref.proxy(datastore), weakref.proxy(this_node), log)

    return rest_app, datastore
Ejemplo n.º 2
0
def get_reencryption_requests(ds: Datastore) -> List[ReencryptionRequest]:
    return ds.query_by(ReencryptionRequest)
Ejemplo n.º 3
0
def get_policy_arrangements(ds: Datastore) -> List[PolicyArrangement]:
    return ds.query_by(PolicyArrangement)
Ejemplo n.º 4
0
def find_policy_arrangements(ds: Datastore) -> DatastoreQueryResult:
    return ds.query_by(PolicyArrangement, writeable=True)
Ejemplo n.º 5
0
def get_work_orders(ds: Datastore) -> List[Workorder]:
    return ds.query_by(Workorder)
Ejemplo n.º 6
0
def find_expired_treasure_maps(ds: Datastore, cutoff: maya.MayaDT) -> DatastoreQueryResult:
    return ds.query_by(TreasureMap,
                       filter_field='expiration',
                       filter_func=lambda expiration: expiration <= cutoff,
                       writeable=True)
Ejemplo n.º 7
0
def find_expired_policies(ds: Datastore, cutoff: maya.MayaDT) -> DatastoreQueryResult:
    return ds.query_by(PolicyArrangement,
                       filter_field='expiration',
                       filter_func=lambda expiration: expiration <= cutoff,
                       writeable=True)