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

refactor(mutelist): use jsonschema on mutelist #6264

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions prowler/lib/mutelist/models.py

This file was deleted.

73 changes: 71 additions & 2 deletions prowler/lib/mutelist/mutelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,81 @@
from abc import ABC, abstractmethod

import yaml
from jsonschema import validate

from prowler.lib.logger import logger
from prowler.lib.mutelist.models import mutelist_schema
from prowler.lib.outputs.common import Status
from prowler.lib.outputs.utils import unroll_dict, unroll_tags

mutelist_schema = {
"type": "object",
"properties": {
"Accounts": {
"type": "object",
"patternProperties": {
".*": {
"type": "object",
"properties": {
"Checks": {
"type": "object",
"patternProperties": {
".*": {
"type": "object",
"properties": {
"Regions": {
"type": "array",
"items": {"type": "string"},
},
"Resources": {
"type": "array",
"items": {"type": "string"},
},
"Tags": {
"type": "array",
"items": {"type": "string"},
},
"Exceptions": {
"type": "object",
"properties": {
"Accounts": {
"type": "array",
"items": {"type": "string"},
},
"Regions": {
"type": "array",
"items": {"type": "string"},
},
"Resources": {
"type": "array",
"items": {"type": "string"},
},
"Tags": {
"type": "array",
"items": {"type": "string"},
},
},
"additionalProperties": False,
},
"Description": {
"type": "string",
},
},
"additionalProperties": False,
}
},
"additionalProperties": False,
},
},
"additionalProperties": False,
}
},
"additionalProperties": False,
}
},
"required": ["Accounts"],
"additionalProperties": False,
}


class Mutelist(ABC):
"""
Expand Down Expand Up @@ -70,7 +139,7 @@ def get_mutelist_file_from_local_file(self, mutelist_path: str):

def validate_mutelist(self) -> bool:
try:
self._mutelist = mutelist_schema.validate(self._mutelist)
validate(self._mutelist, schema=mutelist_schema)
return True
except Exception as error:
logger.error(
Expand Down
Loading