Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dynamic_filters): add dynamic filters system #5973

Merged

Conversation

AdriiiPRodri
Copy link
Contributor

@AdriiiPRodri AdriiiPRodri commented Nov 30, 2024

Context

In this PR I have added the endpoint to get the filters dynamically depending on the findings of a date.

Description

Using the specified date, all the findings of that date and the services and regions associated with them are extracted.

{
    "data": {
        "type": "findings-services-regions",
        "id": null,
        "attributes": {
            "services": [
                "accessanalyzer",
                "account"
            ],
            "regions": [
                "ap-northeast-1",
                "ap-northeast-2",
                "ap-northeast-3",
                "ap-south-1",
                "ap-southeast-1",
                "ap-southeast-2",
                "ca-central-1",
                "eu-central-1",
                "eu-central-2",
                "eu-north-1",
                "eu-south-2",
                "eu-west-1",
                "eu-west-2",
                "eu-west-3",
                "sa-east-1",
                "us-east-1",
                "us-east-2",
                "us-west-1",
                "us-west-2"
            ]
        }
    }
}

image

Checklist

  • Are there new checks included in this PR? No
    • If so, do we need to update permissions for the provider? Please review this carefully.
  • Review if the code is being covered by tests.

License

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@AdriiiPRodri AdriiiPRodri self-assigned this Nov 30, 2024
@AdriiiPRodri AdriiiPRodri requested a review from a team as a code owner November 30, 2024 11:31
Copy link

codecov bot commented Nov 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.86%. Comparing base (9794b5c) to head (c9de0b9).
Report is 6 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5973      +/-   ##
==========================================
+ Coverage   92.78%   92.86%   +0.07%     
==========================================
  Files          58       58              
  Lines        4867     4919      +52     
==========================================
+ Hits         4516     4568      +52     
  Misses        351      351              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@vicferpoy vicferpoy left a comment

Choose a reason for hiding this comment

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

This looks really good, great job! I left a few suggestions and one required change. Feel free to discuss anything since I lack some context about the requirements here.

api/src/backend/api/filters.py Outdated Show resolved Hide resolved
api/src/backend/api/v1/serializers.py Outdated Show resolved Hide resolved
api/src/backend/api/v1/views.py Outdated Show resolved Hide resolved
api/src/backend/api/v1/views.py Outdated Show resolved Hide resolved
api/src/backend/api/v1/views.py Outdated Show resolved Hide resolved
api/src/backend/api/v1/views.py Outdated Show resolved Hide resolved
@vicferpoy
Copy link
Member

@AdriiiPRodri Also, I forgot to mention this filter could be vastly improved using the logic from the inserted_at filter from the base Findings filterset:

    def filter_inserted_at(self, queryset, name, value):
        value = self.maybe_date_to_datetime(value)
        start = uuid7_start(datetime_to_uuid7(value))

        return queryset.filter(id__gte=start).filter(inserted_at__date=value)

Please take a look at how it is done in the base findings filters, because it takes partitioned tables into consideration and improves efficiency by a lot.

@AdriiiPRodri AdriiiPRodri force-pushed the PRWLR-5547-Findings-Dynamic-filters-Regions-and-Services branch 3 times, most recently from d69d415 to 23179d3 Compare November 30, 2024 14:49
@AdriiiPRodri AdriiiPRodri force-pushed the PRWLR-5547-Findings-Dynamic-filters-Regions-and-Services branch 2 times, most recently from 0641d0a to 61f7d3e Compare November 30, 2024 15:57
@AdriiiPRodri
Copy link
Contributor Author

@AdriiiPRodri Also, I forgot to mention this filter could be vastly improved using the logic from the inserted_at filter from the base Findings filterset:

    def filter_inserted_at(self, queryset, name, value):
        value = self.maybe_date_to_datetime(value)
        start = uuid7_start(datetime_to_uuid7(value))

        return queryset.filter(id__gte=start).filter(inserted_at__date=value)

Please take a look at how it is done in the base findings filters, because it takes partitioned tables into consideration and improves efficiency by a lot.

Fixed in the last commit, thanks!

@AdriiiPRodri AdriiiPRodri force-pushed the PRWLR-5547-Findings-Dynamic-filters-Regions-and-Services branch from 61f7d3e to c9de0b9 Compare November 30, 2024 16:01
@snaow snaow merged commit 76b8ac1 into master Nov 30, 2024
12 checks passed
@snaow snaow deleted the PRWLR-5547-Findings-Dynamic-filters-Regions-and-Services branch November 30, 2024 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants