Skip to content

Commit

Permalink
Fix query text output for large queries(#456)
Browse files Browse the repository at this point in the history
  • Loading branch information
bradchiappetta authored Apr 22, 2021
1 parent fdd3f93 commit c97e042
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.8.0
current_version = 0.9.0
tag = True
commit = True

Expand Down
14 changes: 14 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@
Changelog
=========

Version `0.9.0`_
================
**Date**: April 21, 2021

* API client:

* Removed rouge debug statement from analysis command

* CLI

* Fixed query command to display text output for queries with more than 10k results
* Query now limits results to 10 on the text output

Version `0.8.0`_
================
**Date**: March 26, 2021
Expand Down Expand Up @@ -167,3 +180,4 @@ Version `0.2.0`_
.. _`0.6.0`: https://github.com/GreyNoise-Intelligence/pygreynoise/compare/v0.5.0...0.6.0
.. _`0.7.0`: https://github.com/GreyNoise-Intelligence/pygreynoise/compare/v0.6.0...0.7.0
.. _`0.8.0`: https://github.com/GreyNoise-Intelligence/pygreynoise/compare/v0.7.0...0.8.0
.. _`0.9.0`: https://github.com/GreyNoise-Intelligence/pygreynoise/compare/v0.8.0...0.9.0
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
author = "GreyNoise Intelligence"

# The full version, including alpha/beta/rc tags
release = "0.8.0"
release = "0.9.0"


# -- General configuration ---------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def read(fname):

setup(
name="greynoise",
version="0.8.0",
version="0.9.0",
description="Abstraction to interact with GreyNoise API.",
url="https://greynoise.io/",
author="GreyNoise Intelligence",
Expand Down
2 changes: 1 addition & 1 deletion src/greynoise/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
__maintainer__ = "GreyNoise Intelligence"
__email__ = "[email protected]"
__status__ = "BETA"
__version__ = "0.8.0"
__version__ = "0.9.0"
1 change: 0 additions & 1 deletion src/greynoise/api/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ def analyze(self, text):
for ip_address in text_ip_addresses:
result = self.api.riot(ip_address)
if result["riot"]:
print("RIOT IP:" + ip_address)
riot_ip_addresses.append(result["ip"])

noise_ip_addresses = [
Expand Down
2 changes: 1 addition & 1 deletion src/greynoise/cli/subcommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def query(
):
"""Run a GNQL (GreyNoise Query Language) query."""
queries = get_queries(context, input_file, query)
results = [api_client.query(query=query) for query in queries]
results = [api_client.query(query=item) for item in queries]
return results


Expand Down
10 changes: 8 additions & 2 deletions src/greynoise/cli/templates/gnql_query.txt.j2
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
{% import "macros.txt.j2" as macros %}
{% for result in results -%}
{% if result.message and not result.complete %}
{% if result.message == ok %}
{{ result.message }}
{% else %}
{% call macros.header(loop) %}Query{% endcall -%}
Query: {{ result.query }}
Count of IPs Returned: {{ result.count }}
{% if result.count > 10 %}
{{ space }}
This output format is limited to 10 results, for all results use -f json for JSON output.
Additionally, use the stats command to pull just statistics for this query
{% endif %}
{%- if result.data %}
{%- for ip_context in result.data %}
{%- for ip_context in result.data[:10] %}
{{ macros.result_header(loop) }}
{%- include "ip_context_result.txt.j2" %}
{%- endfor %}
Expand Down
2 changes: 2 additions & 0 deletions tests/cli/test_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ class TestGNQLQueryFormatter(object):
║ <header> Query 1 of 1 </header> ║
╚═══════════════════════════╝
Query: <ip_address>
Count of IPs Returned: 1
┌───────────────────────────┐
│ Result 1 of 1 │
Expand Down

0 comments on commit c97e042

Please sign in to comment.