Esempio n. 1
0
def resource_get_all(context, user_id=None, show_deleted=False,
                     limit=None, marker=None, sort_keys=None, sort_dir=None,
                     filters=None, tenant_safe=True):
    query = soft_delete_aware_query(context, models.Resource,
                                    show_deleted=show_deleted)

    if tenant_safe:
        query = query.filter_by(user_id=context.tenant_id)

    elif user_id:
        query = query.filter_by(user_id=user_id)

    if filters is None:
        filters = {}

    sort_key_map = {
        consts.RES_CREATED_AT: models.Resource.created_at.key,
        consts.RES_UPDATED_AT: models.Resource.updated_at.key,
        consts.RES_RESOURCE_TYPE: models.Resource.resource_type.key,
        consts.RES_USER_ID: models.Resource.user_id.key,
    }
    keys = _get_sort_keys(sort_keys, sort_key_map)
    query = db_filters.exact_filter(query, models.Resource, filters)
    return _paginate_query(context, query, models.Node,
                           limit=limit, marker=marker,
                           sort_keys=keys, sort_dir=sort_dir,
                           default_sort_keys=['created_at']).all()
Esempio n. 2
0
def event_get_all(context, user_id=None, limit=None, marker=None,
                  sort_keys=None, sort_dir=None, filters=None,
                  start_time=None, end_time=None, tenant_safe=True,
                  show_deleted=False):
    query = soft_delete_aware_query(context, models.Event,
                                    show_deleted=show_deleted)

    if tenant_safe:
        query = query.filter_by(user_id=context.tenant_id)

    elif user_id:
        query = query.filter_by(user_id=user_id)

    if start_time:
        query = query.filter_by(models.Event.timestamp >= start_time)
    if end_time:
        query = query.filter_by(models.Event.timestamp <= end_time)

    if filters is None:
        filters = {}

    sort_key_map = {
        consts.EVENT_ACTION: models.Event.action.key,
        consts.EVENT_RESOURCE_TYPE: models.Event.resource_type.key,
        consts.EVENT_TIMESTAMP: models.Event.timestamp.key,
        consts.EVENT_USER_ID: models.Event.user_id.key,
    }
    keys = _get_sort_keys(sort_keys, sort_key_map)
    query = db_filters.exact_filter(query, models.Resource, filters)
    return _paginate_query(context, query, models.Node,
                           limit=limit, marker=marker,
                           sort_keys=keys, sort_dir=sort_dir,
                           default_sort_keys=['timestamp']).all()
Esempio n. 3
0
def policy_get_all(context,
                   limit=None,
                   marker=None,
                   sort_keys=None,
                   sort_dir=None,
                   filters=None,
                   show_deleted=False):
    query = soft_delete_aware_query(context,
                                    models.Policy,
                                    show_deleted=show_deleted)

    if filters is None:
        filters = {}

    sort_key_map = {
        consts.POLICY_NAME: models.Policy.name.key,
        consts.POLICY_CREATED_AT: models.Policy.created_at.key,
        consts.POLICY_UPDATED_AT: models.Policy.updated_at.key,
    }
    keys = _get_sort_keys(sort_keys, sort_key_map)

    query = db_filters.exact_filter(query, models.Policy, filters)
    return _paginate_query(context,
                           query,
                           models.Policy,
                           limit=limit,
                           marker=marker,
                           sort_keys=keys,
                           sort_dir=sort_dir,
                           default_sort_keys=['id']).all()
Esempio n. 4
0
def rule_get_all(context,
                 show_deleted=False,
                 limit=None,
                 marker=None,
                 sort_keys=None,
                 sort_dir=None,
                 filters=None):
    query = soft_delete_aware_query(context,
                                    models.Rule,
                                    show_deleted=show_deleted)

    if filters is None:
        filters = {}

    sort_key_map = {
        consts.RULE_NAME: models.Rule.name.key,
        consts.RULE_TYPE: models.Rule.type.key,
        consts.RULE_CREATED_AT: models.Rule.created_at.key,
        consts.RULE_UPDATED_AT: models.Rule.updated_at.key,
    }
    keys = _get_sort_keys(sort_keys, sort_key_map)

    query = db_filters.exact_filter(query, models.Rule, filters)
    return _paginate_query(context,
                           query,
                           models.Rule,
                           limit=limit,
                           marker=marker,
                           sort_keys=keys,
                           sort_dir=sort_dir,
                           default_sort_keys=['created_at']).all()
Esempio n. 5
0
def user_get_all(context,
                 show_deleted=False,
                 limit=None,
                 marker=None,
                 sort_keys=None,
                 sort_dir=None,
                 filters=None):
    query = soft_delete_aware_query(context,
                                    models.User,
                                    show_deleted=show_deleted)

    if filters is None:
        filters = {}

    sort_key_map = {
        consts.USER_CREATED_AT: models.User.created_at.key,
        consts.USER_UPDATED_AT: models.User.updated_at.key,
        consts.USER_BALANCE: models.User.balance.key,
        consts.USER_STATUS: models.User.status.key,
    }
    keys = _get_sort_keys(sort_keys, sort_key_map)

    query = db_filters.exact_filter(query, models.User, filters)
    return _paginate_query(context,
                           query,
                           models.User,
                           limit=limit,
                           marker=marker,
                           sort_keys=keys,
                           sort_dir=sort_dir,
                           default_sort_keys=['id']).all()
Esempio n. 6
0
def event_get_all(context,
                  user_id=None,
                  limit=None,
                  marker=None,
                  sort_keys=None,
                  sort_dir=None,
                  filters=None,
                  start_time=None,
                  end_time=None,
                  tenant_safe=True,
                  show_deleted=False):
    query = soft_delete_aware_query(context,
                                    models.Event,
                                    show_deleted=show_deleted)

    if tenant_safe:
        query = query.filter_by(user_id=context.tenant_id)

    elif user_id:
        query = query.filter_by(user_id=user_id)

    if start_time:
        query = query.filter_by(models.Event.timestamp >= start_time)
    if end_time:
        query = query.filter_by(models.Event.timestamp <= end_time)

    if filters is None:
        filters = {}

    sort_key_map = {
        consts.EVENT_ACTION: models.Event.action.key,
        consts.EVENT_RESOURCE_TYPE: models.Event.resource_type.key,
        consts.EVENT_TIMESTAMP: models.Event.timestamp.key,
        consts.EVENT_USER_ID: models.Event.user_id.key,
    }
    keys = _get_sort_keys(sort_keys, sort_key_map)
    query = db_filters.exact_filter(query, models.Resource, filters)
    return _paginate_query(context,
                           query,
                           models.Node,
                           limit=limit,
                           marker=marker,
                           sort_keys=keys,
                           sort_dir=sort_dir,
                           default_sort_keys=['timestamp']).all()
Esempio n. 7
0
def policy_get_all(context, limit=None, marker=None,
                   sort_keys=None, sort_dir=None,
                   filters=None, show_deleted=False):
    query = soft_delete_aware_query(context, models.Policy,
                                    show_deleted=show_deleted)

    if filters is None:
        filters = {}

    sort_key_map = {
        consts.POLICY_NAME: models.Policy.name.key,
        consts.POLICY_CREATED_AT: models.Policy.created_at.key,
        consts.POLICY_UPDATED_AT: models.Policy.updated_at.key,
    }
    keys = _get_sort_keys(sort_keys, sort_key_map)

    query = db_filters.exact_filter(query, models.Policy, filters)
    return _paginate_query(context, query, models.Policy,
                           limit=limit, marker=marker,
                           sort_keys=keys, sort_dir=sort_dir,
                           default_sort_keys=['id']).all()
Esempio n. 8
0
def rule_get_all(context, show_deleted=False, limit=None,
                 marker=None, sort_keys=None, sort_dir=None,
                 filters=None):
    query = soft_delete_aware_query(context, models.Rule,
                                    show_deleted=show_deleted)

    if filters is None:
        filters = {}

    sort_key_map = {
        consts.RULE_NAME: models.Rule.name.key,
        consts.RULE_TYPE: models.Rule.type.key,
        consts.RULE_CREATED_AT: models.Rule.created_at.key,
        consts.RULE_UPDATED_AT: models.Rule.updated_at.key,
    }
    keys = _get_sort_keys(sort_keys, sort_key_map)

    query = db_filters.exact_filter(query, models.Rule, filters)
    return _paginate_query(context, query, models.Rule,
                           limit=limit, marker=marker,
                           sort_keys=keys, sort_dir=sort_dir,
                           default_sort_keys=['created_at']).all()
Esempio n. 9
0
def user_get_all(context, show_deleted=False, limit=None,
                 marker=None, sort_keys=None, sort_dir=None,
                 filters=None):
    query = soft_delete_aware_query(context, models.User,
                                    show_deleted=show_deleted)

    if filters is None:
        filters = {}

    sort_key_map = {
        consts.USER_CREATED_AT: models.User.created_at.key,
        consts.USER_UPDATED_AT: models.User.updated_at.key,
        consts.USER_BALANCE: models.User.balance.key,
        consts.USER_STATUS: models.User.status.key,
    }
    keys = _get_sort_keys(sort_keys, sort_key_map)

    query = db_filters.exact_filter(query, models.User, filters)
    return _paginate_query(context, query, models.User,
                           limit=limit, marker=marker,
                           sort_keys=keys, sort_dir=sort_dir,
                           default_sort_keys=['id']).all()
Esempio n. 10
0
def resource_get_all(context,
                     user_id=None,
                     show_deleted=False,
                     limit=None,
                     marker=None,
                     sort_keys=None,
                     sort_dir=None,
                     filters=None,
                     tenant_safe=True):
    query = soft_delete_aware_query(context,
                                    models.Resource,
                                    show_deleted=show_deleted)

    if tenant_safe:
        query = query.filter_by(user_id=context.tenant_id)

    elif user_id:
        query = query.filter_by(user_id=user_id)

    if filters is None:
        filters = {}

    sort_key_map = {
        consts.RES_CREATED_AT: models.Resource.created_at.key,
        consts.RES_UPDATED_AT: models.Resource.updated_at.key,
        consts.RES_RESOURCE_TYPE: models.Resource.resource_type.key,
        consts.RES_USER_ID: models.Resource.user_id.key,
    }
    keys = _get_sort_keys(sort_keys, sort_key_map)
    query = db_filters.exact_filter(query, models.Resource, filters)
    return _paginate_query(context,
                           query,
                           models.Node,
                           limit=limit,
                           marker=marker,
                           sort_keys=keys,
                           sort_dir=sort_dir,
                           default_sort_keys=['created_at']).all()