Skip to content

Commit

Permalink
[feat] Load checks by id (#1799)
Browse files Browse the repository at this point in the history
  • Loading branch information
aquamatthias committed Oct 10, 2023
1 parent 8614ef1 commit f098ac5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
7 changes: 7 additions & 0 deletions resotocore/resotocore/static/api-doc.yaml
Expand Up @@ -2711,6 +2711,13 @@ paths:
schema:
type: string
example: "aws_ec2_instance"
- name: id
in: query
description: "Filter by check ids."
schema:
type: string
explode: false
example: "aws_ec2_snapshot_encrypted,aws_ec2_unused_elastic_ip"
responses:
"200":
description: "List of checks."
Expand Down
5 changes: 4 additions & 1 deletion resotocore/resotocore/web/api.py
Expand Up @@ -647,7 +647,10 @@ async def inspection_checks(self, request: Request, deps: TenantDependencies) ->
service = request.query.get("service")
category = request.query.get("category")
kind = request.query.get("kind")
inspections = await deps.inspector.list_checks(provider=provider, service=service, category=category, kind=kind)
check_ids = request.query.get("id", "").split(",")
inspections = await deps.inspector.list_checks(
provider=provider, service=service, category=category, kind=kind, check_ids=check_ids
)
return await single_result(request, to_js(inspections))

async def benchmarks(self, request: Request, deps: TenantDependencies) -> StreamResponse:
Expand Down
17 changes: 15 additions & 2 deletions resotocore/tests/resotocore/web/api_test.py
Expand Up @@ -475,16 +475,29 @@ async def test_config(core_client: ResotoClient, foo_kinds: List[rc.Kind]) -> No
@pytest.mark.asyncio
async def test_report(core_client: ResotoClient, client_session: ClientSession) -> None:
url = core_client.resotocore_url
report = await client_session.get(
response = await client_session.get(
f"{url}/report/benchmarks", params={"with_checks": "true", "short": "true", "benchmarks": "aws_cis_1_5"}
)
benchmarks = await report.json()
benchmarks = await response.json()
assert len(benchmarks) == 1
benchmark = benchmarks[0]
assert benchmark["id"] == "aws_cis_1_5"
assert len(benchmark["report_checks"]) > 50
assert benchmark.get("checks") is None
assert benchmark.get("children") is None
response = await client_session.get(
f"{url}/report/checks",
params=dict(
provider="aws",
service="ec2",
category="security",
kind="aws_ec2_instance",
id="aws_ec2_internet_facing_with_instance_profile,aws_ec2_old_instances,aws_ec2_unused_elastic_ip",
),
)
checks = await response.json()
assert len(checks) == 2
assert {a["id"] for a in checks} == {"aws_ec2_internet_facing_with_instance_profile", "aws_ec2_old_instances"}


@pytest.mark.asyncio
Expand Down

0 comments on commit f098ac5

Please sign in to comment.