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

chore(csv): add CSVOutput class #4315

Open
wants to merge 24 commits into
base: master
Choose a base branch
from

Conversation

pedrooot
Copy link
Member

Description

It's needed to modularize the code for the specific csv output.

License

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

@pedrooot pedrooot requested review from a team as code owners June 25, 2024 10:06
@pedrooot pedrooot changed the title chore(csv): add CSVOutput class WIP chore(csv): add CSVOutput class Jun 25, 2024
@pedrooot pedrooot marked this pull request as draft June 25, 2024 10:07
@pedrooot pedrooot added the no-merge Please, DO NOT MERGE this PR. label Jun 25, 2024
Copy link

codecov bot commented Jun 25, 2024

Codecov Report

Attention: Patch coverage is 51.75439% with 55 lines in your changes missing coverage. Please review.

Project coverage is 87.15%. Comparing base (819a559) to head (7e798d5).
Report is 21 commits behind head on master.

Current head 7e798d5 differs from pull request most recent head 5ccb51d

Please upload reports for the commit 5ccb51d to get more accurate results.

Files Patch % Lines
prowler/lib/outputs/common_models.py 53.65% 38 Missing ⚠️
prowler/__main__.py 0.00% 10 Missing ⚠️
prowler/lib/outputs/outputs.py 33.33% 2 Missing ⚠️
...tputs/compliance/aws_well_architected_framework.py 50.00% 1 Missing ⚠️
prowler/lib/outputs/compliance/ens_rd2022_aws.py 50.00% 1 Missing ⚠️
prowler/lib/outputs/compliance/generic.py 50.00% 1 Missing ⚠️
...rowler/lib/outputs/compliance/iso27001_2013_aws.py 50.00% 1 Missing ⚠️
...ib/outputs/compliance/mitre_attack/mitre_attack.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4315      +/-   ##
==========================================
+ Coverage   86.98%   87.15%   +0.16%     
==========================================
  Files         843      843              
  Lines       26309    26396      +87     
==========================================
+ Hits        22886    23005     +119     
+ Misses       3423     3391      -32     

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

@pedrooot pedrooot marked this pull request as ready for review June 26, 2024 14:24
Copy link
Member

@jfagoagas jfagoagas left a comment

Choose a reason for hiding this comment

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

That's a great piece of work @pedrooot

I left some comments since I'm thinking how to handle a complete output with all the findings and I think I'll remove all the changes in compliance since it is out of the scope of this PR.

@@ -22,78 +23,93 @@ def get_provider_data_mapping(provider) -> dict:
return data


def generate_provider_output(provider, finding, csv_data) -> FindingOutput:
def generate_output(provider, finding, output_options) -> Finding:
Copy link
Member

Choose a reason for hiding this comment

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

What if we move this into the Finding class?

Please also add tests and a docsting to the function to explain inputs, outputs, and what it does.

Copy link
Member Author

@pedrooot pedrooot Jun 27, 2024

Choose a reason for hiding this comment

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

Done for docstring

return finding_output


def generate_provider_output(provider, finding, output_data) -> Finding:
Copy link
Member

Choose a reason for hiding this comment

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

What if we move this into the Finding class?

Please also add tests and a docsting to the function to explain inputs, outputs, and what it does.

Copy link
Member Author

@pedrooot pedrooot Jun 27, 2024

Choose a reason for hiding this comment

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

Done for docstring



class Output(ABC):
_data: object
Copy link
Member

Choose a reason for hiding this comment

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

What if this output holds all the findings?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point!

from prowler.lib.outputs.csv.csv import write_csv


@pytest.fixture
Copy link
Member

Choose a reason for hiding this comment

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

Please create a Test Class here and maybe move it to a folder with the same name as the code within Prowler.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

informational = "informational"


class CSVRow(BaseModel):
Copy link
Member

Choose a reason for hiding this comment

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

Not used anymore.

assert "us-west-1" in content
assert "Description of the finding" in content
assert "High" in content
assert "http://example.com" in content

Check failure

Code scanning / CodeQL

Incomplete URL substring sanitization High

The string
http://example.com
may be at an arbitrary position in the sanitized URL.
Copy link
Member

Choose a reason for hiding this comment

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

Please fix this using ==

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-merge Please, DO NOT MERGE this PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants