Skip to content

Commit

Permalink
Plugins: show details and report issues
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaspatzke committed Oct 27, 2023
1 parent 434ae83 commit 8b983c4
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
36 changes: 35 additions & 1 deletion sigma/cli/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,29 @@ def get_plugin(uuid : bool, plugin_identifier : str) -> SigmaPlugin:
except SigmaPluginNotFoundError as e:
raise click.exceptions.ClickException(str(e))

# Display plugin details
@plugin_group.command(name="show", help="Show details about plugin.")
@click.option("--uuid", "-u", is_flag=True, help="Show plugin by UUID.")
@click.argument("plugin-identifier")
def show_plugin(uuid : bool, plugin_identifier : str):
plugin = get_plugin(uuid, plugin_identifier)
table = PrettyTable()
table.field_names = ("Property", "Value")
table.add_rows([
("Identifier", plugin.id),
("UUID", plugin.uuid),
("Type", str(plugin.type)),
("State", str(plugin.state)),
("Package", plugin.package),
("Description", fill(plugin.description, width=60)),
("Required pySigma version", plugin.pysigma_version),
("Compatible?", plugin.is_compatible()),
("Project URL", plugin.project_url),
("Report Issue URL", plugin.report_issue_url),
])
table.align = "l"
click.echo(table.get_string())

@plugin_group.command(name="install", help="Install plugin by identifier or UUID.")
@click.option("--uuid", "-u", is_flag=True, help="Install plugin by UUID.")
@click.option("--compatibility-check/--no-compatibility-check", "-c/-C", default=True, help="Enable or disable plugin compatibility check.")
Expand All @@ -69,4 +92,15 @@ def uninstall_plugin(uuid : bool, plugin_identifiers : List[str]):
for plugin_identifier in plugin_identifiers:
plugin = get_plugin(uuid, plugin_identifier)
plugin.uninstall()
click.echo(f"Successfully uninstalled plugin '{plugin_identifier}'")
click.echo(f"Successfully uninstalled plugin '{plugin_identifier}'")

# Report issue in plugin by opening the issue reporting URL in the default browser
@plugin_group.command(name="report-issue", help="Report issue in plugin by opening the issue reporting URL in the default browser.")
@click.option("--uuid", "-u", is_flag=True, help="Report issue in plugin by UUID.")
@click.argument("plugin-identifier")
def report_issue(uuid : bool, plugin_identifier : str):
plugin = get_plugin(uuid, plugin_identifier)
if plugin.report_issue_url:
click.launch(plugin.report_issue_url)
else:
raise click.exceptions.ClickException("Plugin does not have an issue reporting URL!")
24 changes: 24 additions & 0 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,30 @@ def test_plugin_list_search():
assert plugin_list_search.exit_code == 0
assert len(plugin_list.output.split()) > len(plugin_list_search.output.split())

def test_plugin_show_help():
cli = CliRunner()
result = cli.invoke(plugin_group, ["show", "--help"])
assert result.exit_code == 0
assert len(result.stdout.split()) > 20

def test_plugin_show_identifier():
cli = CliRunner()
plugin_show = cli.invoke(plugin_group, ["show", "splunk"])
assert plugin_show.exit_code == 0
assert "Splunk" in plugin_show.output

def test_plugin_show_nonexisting():
cli = CliRunner()
plugin_show = cli.invoke(plugin_group, ["show", "notexisting"])
assert plugin_show.exit_code != 0
assert "error" in plugin_show.output.lower()

def test_plugin_show_uuid():
cli = CliRunner()
plugin_show = cli.invoke(plugin_group, ["show", "-u", "4af37b53-f1ec-4567-8017-2fb9315397a1"])
assert plugin_show.exit_code == 0
assert "Splunk" in plugin_show.output

def test_plugin_install_notexisting():
cli = CliRunner()
result = cli.invoke(install_plugin, ["notexisting"])
Expand Down

0 comments on commit 8b983c4

Please sign in to comment.