Skip to content

Commit

Permalink
Removed unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
Singha22 committed Jan 27, 2025
1 parent 91fcb8e commit 0365a40
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 47 deletions.
42 changes: 2 additions & 40 deletions moto/securityhub/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,6 @@ def __init__(self, finding_id: str, finding_data: Dict[str, Any]):
self.id = finding_id
self.data = finding_data

# # Ensure required fields exist with default values
# self.data.setdefault("Id", finding_id)
# self.data.setdefault("AwsAccountId", "")
# self.data.setdefault("CreatedAt", "")
# self.data.setdefault("Description", "")
# self.data.setdefault("GeneratorId", "")
# self.data.setdefault("ProductArn", "")
# self.data.setdefault("Title", "")
# self.data.setdefault("Types", [])

# # Required but with nested structure
# self.data.setdefault("Severity", {"Label": ""})
# self.data.setdefault("Resources", [])

# # Optional fields with default values
# self.data.setdefault("UpdatedAt", "")
# self.data.setdefault("FirstObservedAt", "")
# self.data.setdefault("LastObservedAt", "")
# self.data.setdefault("Confidence", 0)
# self.data.setdefault("Criticality", 0)
# self.data.setdefault("RecordState", "ACTIVE")
# self.data.setdefault("WorkflowState", "NEW")
# self.data.setdefault("VerificationState", "UNKNOWN")

# def _get_sortable_value(self, field: str) -> Any:
# """Get a value from the finding data using dot notation"""
# if "." in field:
# parent, child = field.split(".")
# return self.data.get(parent, {}).get(child)
# elif "/" in field:
# parent, child = field.split("/")
# return self.data.get(parent, {}).get(child)
# return self.data.get(field)

def as_dict(self) -> Dict[str, Any]:
return self.data

Expand All @@ -64,10 +30,9 @@ def get_findings(
next_token: Optional[str] = None,
max_results: Optional[int] = None,
) -> Dict[str, Any]:
"""Gets findings from SecurityHub based on provided filters and sorting criteria"""
findings = self.findings

# Validate max_results if provided
# Max Results Parameter
if max_results is not None:
try:
max_results = int(max_results)
Expand All @@ -81,7 +46,7 @@ def get_findings(
op="GetFindings", msg="MaxResults must be a number greater than 0"
)

# Handle pagination
# next_token Parameter
if next_token:
start_idx = int(next_token)

Check warning on line 51 in moto/securityhub/models.py

View check run for this annotation

Codecov / codecov/patch

moto/securityhub/models.py#L51

Added line #L51 was not covered by tests
else:
Expand All @@ -93,7 +58,6 @@ def get_findings(

paginated_findings = findings[start_idx:end_idx]

# Generate next token if there are more results
next_token = str(end_idx) if end_idx < len(findings) else None

return {
Expand Down Expand Up @@ -135,10 +99,8 @@ def batch_import_findings(
)

if existing_finding:
# Update existing finding
existing_finding.data.update(finding_data)

Check warning on line 102 in moto/securityhub/models.py

View check run for this annotation

Codecov / codecov/patch

moto/securityhub/models.py#L102

Added line #L102 was not covered by tests
else:
# Create new finding
new_finding = Finding(finding_id, finding_data)
self.findings.append(new_finding)

Expand Down
1 change: 0 additions & 1 deletion moto/securityhub/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def securityhub_backend(self) -> SecurityHubBackend:
def get_findings(self) -> str:
raw_params = self._get_params()

# Parse the JSON string that's being used as a key
params = json.loads(next(iter(raw_params.keys()), "{}"))

sort_criteria = params.get("SortCriteria", [])
Expand Down
6 changes: 0 additions & 6 deletions tests/test_securityhub/test_securityhub.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@ def test_get_findings():
"Types": ["Software and Configuration Checks"],
}

# Import the finding
import_response = client.batch_import_findings(Findings=[test_finding])
assert import_response["SuccessCount"] == 1

# Get the findings
response = client.get_findings()

assert "Findings" in response
Expand All @@ -40,8 +38,6 @@ def test_get_findings():
finding = response["Findings"][0]
assert finding["Id"] == "test-finding-001"
assert finding["SchemaVersion"] == "2018-10-08"
# assert finding["WorkflowState"] == "NEW"
# assert finding["RecordState"] == "ACTIVE"


@mock_aws
Expand Down Expand Up @@ -81,10 +77,8 @@ def test_batch_import_findings():

@mock_aws
def test_get_findings_invalid_parameters():
"""Test getting findings with invalid parameters."""
client = boto3.client("securityhub", region_name="us-east-1")

# Test invalid MaxResults (must be between 1 and 100)
with pytest.raises(ClientError) as exc:
client.get_findings(MaxResults=101)

Expand Down

0 comments on commit 0365a40

Please sign in to comment.