def test_try_get_default_header_raises_cli_error_when_using_include_all_with_none_table_format(
):
    with pytest.raises(errors.Code42CLIError) as err:
        try_get_default_header(True, {}, OutputFormat.CSV)

    assert str(
        err.value) == "--include-all only allowed for Table output format."
def search(
    state,
    format,
    begin,
    end,
    advanced_query,
    use_checkpoint,
    saved_search,
    or_query,
    include_all,
    **kwargs,
):
    """Search for file events."""
    output_header = ext.try_get_default_header(include_all,
                                               SEARCH_DEFAULT_HEADER, format)

    formatter = FileEventsOutputFormatter(format, output_header)
    cursor = (_get_file_event_cursor_store(state.profile.name)
              if use_checkpoint else None)
    handlers = ext.create_handlers(
        state.sdk,
        FileEventExtractor,
        cursor,
        use_checkpoint,
        formatter=formatter,
        force_pager=include_all,
    )
    _call_extractor(state, handlers, begin, end, or_query, advanced_query,
                    saved_search, **kwargs)

    handle_no_events(not handlers.TOTAL_EVENTS and not errors.ERRORED)
def search(
    state,
    format,
    begin,
    end,
    advanced_query,
    use_checkpoint,
    saved_search,
    or_query,
    include_all,
    **kwargs,
):
    """Search for file events."""
    output_header = ext.try_get_default_header(include_all,
                                               _create_search_header_map(),
                                               format)
    formatter = FileEventsOutputFormatter(format, output_header)
    cursor = _get_cursor(state, use_checkpoint)
    handlers = ext.create_handlers(
        state.sdk,
        FileEventExtractor,
        cursor,
        use_checkpoint,
        formatter=formatter,
        force_pager=include_all,
    )
    _extract(state, handlers, begin, end, or_query, advanced_query,
             saved_search, **kwargs)
Exemple #4
0
def search(
    cli_state,
    format,
    begin,
    end,
    advanced_query,
    use_checkpoint,
    or_query,
    include_all,
    **kwargs,
):
    """Search for alerts."""
    output_header = ext.try_get_default_header(include_all,
                                               _get_default_output_header(),
                                               format)
    formatter = OutputFormatter(format, output_header)
    cursor = _get_alert_cursor_store(
        cli_state.profile.name) if use_checkpoint else None
    handlers = ext.create_handlers(
        cli_state.sdk,
        AlertExtractor,
        cursor,
        use_checkpoint,
        formatter=formatter,
        force_pager=include_all,
    )
    _call_extractor(cli_state, handlers, begin, end, or_query, advanced_query,
                    **kwargs)
    handle_no_events(not handlers.TOTAL_EVENTS and not errors.ERRORED)
def test_try_get_default_header_returns_none_when_is_table_and_told_to_include_all(
):
    default_header = {"default": "header"}
    actual = try_get_default_header(True, default_header, OutputFormat.TABLE)
    assert actual is None
def test_try_get_default_header_uses_default_header_when_not_include_all():
    default_header = {"default": "header"}
    actual = try_get_default_header(False, default_header, OutputFormat.TABLE)
    assert actual is default_header