How to use the greynoise.cli.subcommand function in greynoise

To help you get started, we’ve selected a few greynoise examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github GreyNoise-Intelligence / pygreynoise / tests / cli / test_subcommand.py View on Github external
def test_requests_exception(self, api_client):
        """Error is displayed on requests library exception."""
        runner = CliRunner()
        expected = "API error: \n"

        api_client.filter.side_effect = RequestException("")
        result = runner.invoke(subcommand.filter, input="some text")
        assert result.exit_code == -1
        assert result.output == expected
github GreyNoise-Intelligence / pygreynoise / tests / cli / test_subcommand.py View on Github external
def test_help(self):
        """Get help."""
        runner = CliRunner()
        expected_output = "Usage: greynoise [OPTIONS] COMMAND [ARGS]..."

        result = runner.invoke(
            subcommand.help_, parent=Context(main, info_name="greynoise")
        )
        assert result.exit_code == 0
        assert expected_output in result.output
github GreyNoise-Intelligence / pygreynoise / tests / cli / test_subcommand.py View on Github external
def test_no_ip_address_passed(self, api_client):
        """Usage is returned if no IP address or input file is passed."""
        runner = CliRunner()

        with patch("greynoise.cli.helper.sys") as sys:
            sys.stdin.isatty.return_value = True
            result = runner.invoke(
                subcommand.quick, parent=Context(main, info_name="greynoise")
            )
        assert result.exit_code == -1
        assert "Usage: greynoise quick" in result.output
        api_client.quick.assert_not_called()
github GreyNoise-Intelligence / pygreynoise / tests / cli / test_subcommand.py View on Github external
def test_input_file(self, api_client, ip_address, expected_response):
        """Report IP address as "interesting" from input file."""
        runner = CliRunner()

        api_client.interesting.return_value = expected_response

        result = runner.invoke(subcommand.interesting, ["-i", StringIO(ip_address)])
        assert result.exit_code == 0
        assert result.output == ""
        api_client.interesting.assert_called_with(ip_address=ip_address)
github GreyNoise-Intelligence / pygreynoise / tests / cli / test_subcommand.py View on Github external
def test_not_implemented(self, api_client):
        """Not implemented error message returned."""
        runner = CliRunner()
        expected_output = "Error: 'alerts' subcommand is not implemented yet.\n"

        api_client.not_implemented.side_effect = RequestFailure(501)
        result = runner.invoke(subcommand.alerts)
        api_client.not_implemented.assert_called_with("alerts")
        assert result.exit_code == 1
        assert result.output == expected_output
github GreyNoise-Intelligence / pygreynoise / tests / cli / test_subcommand.py View on Github external
def test_not_implemented(self, api_client):
        """Not implemented error message returned."""
        runner = CliRunner()
        expected_output = "Error: 'account' subcommand is not implemented yet.\n"

        api_client.not_implemented.side_effect = RequestFailure(501)
        result = runner.invoke(subcommand.account)
        api_client.not_implemented.assert_called_with("account")
        assert result.exit_code == 1
        assert result.output == expected_output
github GreyNoise-Intelligence / pygreynoise / tests / cli / test_subcommand.py View on Github external
def test_missing_api_key(self):
        """Setup fails when api_key is not passed."""
        runner = CliRunner()
        expected_error = 'Error: Missing option "-k" / "--api-key"'

        result = runner.invoke(subcommand.setup, [])
        assert result.exit_code == 2
        assert expected_error in result.output
github GreyNoise-Intelligence / pygreynoise / tests / cli / test_subcommand.py View on Github external
def test_requests_exception(self, api_client):
        """Error is displayed on requests library exception."""
        runner = CliRunner()
        expected = "API error: \n"

        api_client.analyze.side_effect = RequestException("")
        result = runner.invoke(subcommand.analyze, input="some text")
        assert result.exit_code == -1
        assert result.output == expected
github GreyNoise-Intelligence / pygreynoise / tests / cli / test_subcommand.py View on Github external
def test_not_implemented(self, api_client):
        """Not implemented error message returned."""
        runner = CliRunner()
        expected_output = "Error: 'signature' subcommand is not implemented yet.\n"

        api_client.not_implemented.side_effect = RequestFailure(501)
        result = runner.invoke(subcommand.signature)
        api_client.not_implemented.assert_called_with("signature")
        assert result.exit_code == 1
        assert result.output == expected_output
github GreyNoise-Intelligence / pygreynoise / src / greynoise / cli / __init__.py View on Github external
@click.group(
    cls=DefaultGroup,
    default="query",
    default_if_no_args=False,
    context_settings={"help_option_names": ("-h", "--help")},
)
def main():
    """GreyNoise CLI."""
    if not structlog.is_configured():
        configure_logging()


SUBCOMMAND_FUNCTIONS = [
    subcommand_function
    for subcommand_function in vars(subcommand).values()
    if isinstance(subcommand_function, click.Command)
]

for subcommand_function in SUBCOMMAND_FUNCTIONS:
    main.add_command(subcommand_function)

register_repl(main)