Пример #1
0
def delete_group(feed, group):
    session = db.get_session()
    try:
        f = db.lookup_feed_group(db_session=session, feed_name=feed, group_name=group)
        if not f:
            raise ResourceNotFound(group, detail={})
        elif f.enabled:
            raise ConflictingRequest(message='Cannot delete an enabled feed group. Disable the feed group first', detail={})
    except AnchoreApiError:
        raise
    except Exception as e:
        return jsonify(make_response_error(e, in_httpcode=500)), 500
    finally:
        session.rollback()

    try:
        g = sync.DataFeeds.delete_feed_group(feed_name=feed, group_name=group)
        log.info('Flushed group records {}'.format(g))
        if g:
            return jsonify(_marshall_group_response(g)), 200
        else:
            raise ResourceNotFound(group, detail={})
    except KeyError as e:
        raise ResourceNotFound(resource=str(e), detail={'feed': feed, 'group': group})
    except AnchoreApiError:
        raise
    except Exception as e:
        log.error('Could not flush feed group {}/{}'.format(feed, group))
        return jsonify(make_response_error(e, in_httpcode=500)), 500
Пример #2
0
def delete_feed(feed):
    session = db.get_session()
    try:
        f = db.lookup_feed(db_session=session, feed_name=feed)
        if not f:
            raise ResourceNotFound(resource=feed, detail={})
        elif f.enabled:
            raise ConflictingRequest(
                message="Cannot delete an enabled feed. Disable the feed first",
                detail={},
            )
    except AnchoreApiError:
        raise
    except Exception as e:
        return jsonify(make_response_error(e, in_httpcode=500)), 500
    finally:
        session.rollback()

    try:
        f = sync.DataFeeds.delete_feed(feed)
        if f:
            return jsonify(_marshall_feed_response(f).to_json()), 200
        else:
            raise ResourceNotFound(feed, detail={})
    except KeyError as e:
        raise ResourceNotFound(resource=str(e), detail={"feed": feed})
    except AnchoreApiError:
        raise
    except Exception as e:
        return jsonify(make_response_error(e, in_httpcode=500)), 500
Пример #3
0
def delete_group(feed, group):
    if feed == GRYPE_DB_FEED_NAME:
        raise HTTPNotImplementedError(
            message=
            "Deleting individual groups for the grypedb feed is not yet supported.",
            detail={},
        )
    session = db.get_session()
    try:
        f = db.lookup_feed_group(db_session=session,
                                 feed_name=feed,
                                 group_name=group)
        if not f:
            raise ResourceNotFound(group, detail={})
        elif f.enabled:
            raise ConflictingRequest(
                message=
                "Cannot delete an enabled feed group. Disable the feed group first",
                detail={},
            )
    except AnchoreApiError:
        raise
    except Exception as e:
        return jsonify(make_response_error(e, in_httpcode=500)), 500
    finally:
        session.rollback()

    try:
        g = sync.DataFeeds.delete_feed_group(feed_name=feed, group_name=group)
        log.info("Flushed group records {}".format(g))
        if g:
            return jsonify(_marshall_group_response(g).to_json()), 200
        else:
            raise ResourceNotFound(group, detail={})
    except KeyError as e:
        raise ResourceNotFound(resource=str(e),
                               detail={
                                   "feed": feed,
                                   "group": group
                               })
    except AnchoreApiError:
        raise
    except Exception as e:
        log.error("Could not flush feed group {}/{}".format(feed, group))
        return jsonify(make_response_error(e, in_httpcode=500)), 500