diff --git a/prowler/CHANGELOG.md b/prowler/CHANGELOG.md index 2fdc2a72ef..febd135306 100644 --- a/prowler/CHANGELOG.md +++ b/prowler/CHANGELOG.md @@ -24,6 +24,7 @@ All notable changes to the **Prowler SDK** are documented in this file. - Add search bar in Dashboard Overview page. [(#7804)](https://github.com/prowler-cloud/prowler/pull/7804) - Add `storage_account_key_access_disabled` check for Azure provider. [(#7974)](https://github.com/prowler-cloud/prowler/pull/7974) - Add `storage_ensure_file_shares_soft_delete_is_enabled` check for Azure provider. [(#7966)](https://github.com/prowler-cloud/prowler/pull/7966) +- Make `validate_mutelist` method static inside `Mutelist` class. [(#7811)](https://github.com/prowler-cloud/prowler/pull/7811) ### Fixed - Add github provider to `usage` section of `prowler -h`: [(#7906)](https://github.com/prowler-cloud/prowler/pull/7906) diff --git a/prowler/lib/mutelist/mutelist.py b/prowler/lib/mutelist/mutelist.py index 70f74a2ff5..4940d0202f 100644 --- a/prowler/lib/mutelist/mutelist.py +++ b/prowler/lib/mutelist/mutelist.py @@ -98,7 +98,6 @@ class Mutelist(ABC): mutelist_file_path: Property that returns the mutelist file path. is_finding_muted: Abstract method to check if a finding is muted. get_mutelist_file_from_local_file: Retrieves the mutelist file from a local file. - validate_mutelist: Validates the mutelist against a schema. is_muted: Checks if a finding is muted for the audited account, check, region, resource, and tags. is_muted_in_check: Checks if a check is muted. is_excepted: Checks if the account, region, resource, and tags are excepted based on the exceptions. @@ -119,7 +118,7 @@ class Mutelist(ABC): self._mutelist = mutelist_content if self._mutelist: - self.validate_mutelist() + self._mutelist = Mutelist.validate_mutelist(self._mutelist) @property def mutelist(self) -> dict: @@ -142,17 +141,6 @@ class Mutelist(ABC): f"{error.__class__.__name__} -- {error}[{error.__traceback__.tb_lineno}]" ) - def validate_mutelist(self) -> bool: - try: - validate(self._mutelist, schema=mutelist_schema) - return True - except Exception as error: - logger.error( - f"{error.__class__.__name__} -- Mutelist YAML is malformed - {error}[{error.__traceback__.tb_lineno}]" - ) - self._mutelist = {} - return False - def is_muted( self, audited_account: str, @@ -449,3 +437,23 @@ class Mutelist(ABC): f"{error.__class__.__name__} -- {error}[{error.__traceback__.tb_lineno}]" ) return False + + @staticmethod + def validate_mutelist(mutelist: dict) -> dict: + """ + Validate the mutelist against the schema. + + Args: + mutelist (dict): The mutelist to be validated. + + Returns: + dict: The mutelist itself. + """ + try: + validate(mutelist, schema=mutelist_schema) + return mutelist + except Exception as error: + logger.error( + f"{error.__class__.__name__} -- Mutelist YAML is malformed - {error}[{error.__traceback__.tb_lineno}]" + ) + return {} diff --git a/prowler/providers/aws/lib/mutelist/mutelist.py b/prowler/providers/aws/lib/mutelist/mutelist.py index 3302a13f5d..c914400fb7 100644 --- a/prowler/providers/aws/lib/mutelist/mutelist.py +++ b/prowler/providers/aws/lib/mutelist/mutelist.py @@ -41,7 +41,7 @@ class AWSMutelist(Mutelist): else: self.get_mutelist_file_from_local_file(mutelist_path) if self._mutelist: - self.validate_mutelist() + self._mutelist = self.validate_mutelist(self._mutelist) def is_finding_muted( self, diff --git a/tests/providers/aws/lib/mutelist/aws_mutelist_test.py b/tests/providers/aws/lib/mutelist/aws_mutelist_test.py index 51e6890852..29a987e752 100644 --- a/tests/providers/aws/lib/mutelist/aws_mutelist_test.py +++ b/tests/providers/aws/lib/mutelist/aws_mutelist_test.py @@ -304,7 +304,7 @@ class TestAWSMutelist: mutelist = AWSMutelist(mutelist_content=mutelist_fixture) - assert mutelist.validate_mutelist() + assert len(mutelist.validate_mutelist(mutelist_fixture)) > 0 assert mutelist.mutelist == mutelist_fixture def test_validate_mutelist_not_valid_key(self): @@ -317,7 +317,7 @@ class TestAWSMutelist: mutelist = AWSMutelist(mutelist_content=mutelist_fixture) - assert not mutelist.validate_mutelist() + assert len(mutelist.validate_mutelist(mutelist_fixture)) == 0 assert mutelist.mutelist == {} assert mutelist.mutelist_file_path is None diff --git a/tests/providers/azure/lib/mutelist/azure_mutelist_test.py b/tests/providers/azure/lib/mutelist/azure_mutelist_test.py index 3488beb54f..7852aa54d2 100644 --- a/tests/providers/azure/lib/mutelist/azure_mutelist_test.py +++ b/tests/providers/azure/lib/mutelist/azure_mutelist_test.py @@ -36,7 +36,7 @@ class TestAzureMutelist: mutelist = AzureMutelist(mutelist_content=mutelist_fixture) - assert not mutelist.validate_mutelist() + assert len(mutelist.validate_mutelist(mutelist_fixture)) == 0 assert mutelist.mutelist == {} assert mutelist.mutelist_file_path is None diff --git a/tests/providers/gcp/lib/mutelist/gcp_mutelist_test.py b/tests/providers/gcp/lib/mutelist/gcp_mutelist_test.py index 0471c5f0f1..01d3d1abfa 100644 --- a/tests/providers/gcp/lib/mutelist/gcp_mutelist_test.py +++ b/tests/providers/gcp/lib/mutelist/gcp_mutelist_test.py @@ -34,7 +34,7 @@ class TestGCPMutelist: mutelist = GCPMutelist(mutelist_content=mutelist_fixture) - assert not mutelist.validate_mutelist() + assert len(mutelist.validate_mutelist(mutelist_fixture)) == 0 assert mutelist.mutelist == {} assert mutelist.mutelist_file_path is None diff --git a/tests/providers/github/lib/mutelist/github_mutelist_test.py b/tests/providers/github/lib/mutelist/github_mutelist_test.py index 8b8cc803fd..b29db60c07 100644 --- a/tests/providers/github/lib/mutelist/github_mutelist_test.py +++ b/tests/providers/github/lib/mutelist/github_mutelist_test.py @@ -36,7 +36,7 @@ class TestGithubMutelist: mutelist = GithubMutelist(mutelist_content=mutelist_fixture) - assert not mutelist.validate_mutelist() + assert len(mutelist.validate_mutelist(mutelist_fixture)) == 0 assert mutelist.mutelist == {} assert mutelist.mutelist_file_path is None diff --git a/tests/providers/kubernetes/lib/mutelist/kubernetes_mutelist_test.py b/tests/providers/kubernetes/lib/mutelist/kubernetes_mutelist_test.py index 7cc1ae394d..847c82aae8 100644 --- a/tests/providers/kubernetes/lib/mutelist/kubernetes_mutelist_test.py +++ b/tests/providers/kubernetes/lib/mutelist/kubernetes_mutelist_test.py @@ -36,7 +36,7 @@ class TestKubernetesMutelist: mutelist = KubernetesMutelist(mutelist_content=mutelist_fixture) - assert not mutelist.validate_mutelist() + assert len(mutelist.validate_mutelist(mutelist_fixture)) == 0 assert mutelist.mutelist == {} assert mutelist.mutelist_file_path is None diff --git a/tests/providers/m365/lib/mutelist/m365_mutelist_test.py b/tests/providers/m365/lib/mutelist/m365_mutelist_test.py index 8df9a97292..a079666ce8 100644 --- a/tests/providers/m365/lib/mutelist/m365_mutelist_test.py +++ b/tests/providers/m365/lib/mutelist/m365_mutelist_test.py @@ -34,7 +34,7 @@ class TestM365Mutelist: mutelist = M365Mutelist(mutelist_content=mutelist_fixture) - assert not mutelist.validate_mutelist() + assert len(mutelist.validate_mutelist(mutelist_fixture)) == 0 assert mutelist.mutelist == {} assert mutelist.mutelist_file_path is None diff --git a/tests/providers/nhn/lib/mutelist/nhn_mutelist_test.py b/tests/providers/nhn/lib/mutelist/nhn_mutelist_test.py index dcdc17b2d9..48444c622b 100644 --- a/tests/providers/nhn/lib/mutelist/nhn_mutelist_test.py +++ b/tests/providers/nhn/lib/mutelist/nhn_mutelist_test.py @@ -34,7 +34,7 @@ class TestNHNMutelist: mutelist = NHNMutelist(mutelist_content=mutelist_fixture) - assert not mutelist.validate_mutelist() + assert len(mutelist.validate_mutelist(mutelist_fixture)) == 0 assert mutelist.mutelist == {} assert mutelist.mutelist_file_path is None