Skip to content

Commit

Permalink
Add new commands to support latest API endpoints (#1524)
Browse files Browse the repository at this point in the history
* Add new commands to support latest API endpoints (reporting)
* Update docker-compose to docker compose
  • Loading branch information
jleaniz authored Aug 3, 2024
1 parent bd51a8f commit 1ff3ddf
Show file tree
Hide file tree
Showing 7 changed files with 362 additions and 152 deletions.
231 changes: 179 additions & 52 deletions turbinia/api/cli/poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions turbinia/api/cli/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "turbinia-client"
version = "1.0.7"
version = "1.0.8"
description = "Turbinia command-line tool"
authors = ["Turbinia Developers <turbinia-dev@googlegroups.com>"]
maintainers = ["Turbinia Developers <turbinia-dev@googlegroups.com>"]
Expand All @@ -15,7 +15,7 @@ turbinia-client = "turbinia_client.turbiniacli_tool:main"
[tool.poetry.dependencies]
python = "^3.9"
click = "^8.1.7"
turbinia-api-lib = "^1.0.3"
turbinia-api-lib = "^1.0.5"
google-auth-oauthlib = "^1.1.0"
pandas = "^2.1.0"
httpx = "^0.27.0"
Expand Down
52 changes: 52 additions & 0 deletions turbinia/api/cli/turbinia_client/core/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,21 @@ def get_api_server_version(ctx: click.Context) -> None:
f'when calling get_version: {exception.body}')


@groups.config_group.command('download')
@click.pass_context
def get_config_download(ctx: click.Context) -> None:
"""Downloads current Turbinia config from the API server."""
client: api_client.ApiClient = ctx.obj.api_client
api_instance = turbinia_configuration_api.TurbiniaConfigurationApi(client)
try:
api_response = api_instance.download_config()
click.echo(api_response)
except exceptions.ApiException as exception:
log.error(
f'Received status code {exception.status} '
f'when calling download_config: {exception.body}')


@groups.result_group.command('request')
@click.pass_context
@click.argument('request_id')
Expand Down Expand Up @@ -501,3 +516,40 @@ def version():
"""Returns the turbinia-client package distribution version."""
cli_version = importlib_version('turbinia-client')
click.echo(f'turbinia-client version {cli_version}')


@groups.report_group.command('request')
@click.pass_context
@click.argument('request_id')
def get_request_report(ctx: click.Context, request_id: str) -> None:
"""Gets Turbinia request Markdown report.
This command will not do any filtering since this is provided in
the `status request` command via --priority_filter
"""
client: api_client.ApiClient = ctx.obj.api_client
api_instance = turbinia_requests_api.TurbiniaRequestsApi(client)
try:
api_response = api_instance.get_request_report(request_id)
click.echo(api_response)
except exceptions.ApiException as exception:
log.error(
f'Received status code {exception.status} '
f'when calling get_request_report: {exception.body}')


@groups.report_group.command('task')
@click.pass_context
@click.argument('task_id')
def get_task_report(ctx: click.Context, task_id: str) -> None:
"""Gets Turbinia task Markdown report."""
client: api_client.ApiClient = ctx.obj.api_client
api_instance = turbinia_tasks_api.TurbiniaTasksApi(client)
try:
api_response = api_instance.get_task_report(task_id)
click.echo(api_response)
except exceptions.ApiException as exception:
log.error(
f'Received status code {exception.status} '
f'when calling get_request_report: {exception.body}')
7 changes: 6 additions & 1 deletion turbinia/api/cli/turbinia_client/core/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,16 @@ def jobs_group():
"""Get a list of enabled Turbinia jobs."""


@click.group('report')
def report_group():
"""Get reports for Tasks or Requests."""


@click.pass_context
def setup_submit(ctx: click.Context):
try:
ctx.obj.evidence_mapping = ctx.obj.get_evidence_arguments()
ctx.obj.request_options = ctx.obj.get_request_options()

# Build all the commands based on responses from the API server.
request_commands = factory.CommandFactory.create_dynamic_objects(
evidence_mapping=ctx.obj.evidence_mapping,
Expand All @@ -77,3 +81,4 @@ def submit_group(ctx: click.Context):
of available evidence types.
"""
ctx.invoke(setup_submit)
click.echo(submit_group.get_help(ctx))
1 change: 1 addition & 0 deletions turbinia/api/cli/turbinia_client/turbiniacli_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def main():
cli.add_command(groups.jobs_group)
cli.add_command(groups.result_group)
cli.add_command(groups.status_group)
cli.add_command(groups.report_group)
cli.add_command(version)
try:
cli.main()
Expand Down
Loading

0 comments on commit 1ff3ddf

Please sign in to comment.