Skip to content

feat: expose IoC-Sensor relationship in API responses#999

Draft
aashnaachaudhary10 wants to merge 12 commits intointelowlproject:developfrom
aashnaachaudhary10:feature/ioc-sensor-api-final
Draft

feat: expose IoC-Sensor relationship in API responses#999
aashnaachaudhary10 wants to merge 12 commits intointelowlproject:developfrom
aashnaachaudhary10:feature/ioc-sensor-api-final

Conversation

@aashnaachaudhary10
Copy link

@aashnaachaudhary10 aashnaachaudhary10 commented Mar 9, 2026

Description

This PR addresses the requirement to expose the relationship between Indicators of Compromise (IoCs) and their reporting Sensors in the API responses. By updating the IOCSerializer, we now include a sensors field that lists the addresses of all sensors associated with a specific IoC using a SlugRelatedField.

This branch has been re-created based on the latest develop branch to ensure a clean commit history and compatibility with the current project structure.

Related Issues

Type of Change

  • New feature (non-breaking change which adds functionality)

Checklist

  • My branch is based on develop
  • I have verified the changes manually using the Django shell
  • Linter (Ruff) gave 0 errors

Verification Proof (Manual Testing)

I verified the serializer output within the Docker environment (greedybear_uwsgi container):
Screenshot 2026-03-09 204322

from api.serializers import IOCSerializer
from greedybear.models import IOC, Sensor

# Test data setup
s, _ = Sensor.objects.get_or_create(address="10.0.0.1")
i, _ = IOC.objects.get_or_create(name="1.2.3.4", type="ip")
i.sensors.add(s)

# Serialization test
data = IOCSerializer(i).data
print(data['sensors'])
# Output: ['10.0.0.1']

@aashnaachaudhary10 aashnaachaudhary10 force-pushed the feature/ioc-sensor-api-final branch from a443ca2 to 5b6d30f Compare March 9, 2026 15:24
@aashnaachaudhary10
Copy link
Author

@regulartim ,please have a look and tell me if any change required.

@regulartim
Copy link
Collaborator

@regulartim ,please have a look and tell me if any change required.

Hey @aashnaachaudhary10 ! First of all, the CI should not fail! ;) Please fix that.

@aashnaachaudhary10
Copy link
Author

@regulartim ,please have a look and tell me if any change required.

Hey @aashnaachaudhary10 ! First of all, the CI should not fail! ;) Please fix that.

Hi @regulartim I've updated the IOCSerializer to include the sensors field as requested. However, I see one CI test failing. It seems like it might be related to the expected response schema in the tests. Could you please guide if I should update the test cases as well?

@drona-gyawali
Copy link
Contributor

However, I see one CI test failing.

Hi! I haven't gone through code changes , but looking at your CI error, it's clear the failure is coming from the linter rather than the functional tests.

It looks like the code in api/serializers.py just needs to be reformatted to match the project's style. You can fix this locally and prevent it from happening again by setting up the pre-commit hooks as mentioned in the docs

@aashnaachaudhary10
Copy link
Author

Hi @drona-gyawali , thank you for pointing that out! I've now configured pre-commit with Ruff as per the documentation to ensure the formatting matches the project's style. I'm also updating the test cases to fix the backend test failure. Really appreciate the help!

Copy link
Collaborator

@regulartim regulartim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @aashnaachaudhary10 ! You included the filed in the serializer, but this does not automatically expose it in the API responses, right? Did you test the API response? Did it contain the relation? Maybe add a test for that! Also, it seems like you included a lot of unrelated changes in this PR.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file does not belong into this PR.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file also doesn't belong into this PR!

@aashnaachaudhary10
Copy link
Author

Hi @regulartim , thank you for the feedback!

I have just removed the unrelated files (.vscode/settings.json and package-lock.json) that were accidentally included.

I did verify the response manually in the Docker environment (as shown in the screenshot in my description), and the sensors field was correctly populated with the sensor addresses.

Aut I understand the importance of an automated test for this. I will add a test case to verify this relationship in the API response shortly and update the PR.

Thanks for your patience!

Copy link
Collaborator

@regulartim regulartim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @aashnaachaudhary10 ! Now you completely removed the package-lock.json. But it is needed for building the frontend. Also, I still don't see how your changes will expose the relationship in the API.

This PR is far from being ready to merge. Please take your time to understand the task, understand the project setup and how to work with Git. Make sure your PR is flawless before requesting a review again.

@regulartim regulartim marked this pull request as draft March 21, 2026 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants