Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
lirshindalman committed Jul 25, 2024
1 parent ed4edd1 commit 7dd21af
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions checkov/common/graph/checks_infra/solvers/base_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
if TYPE_CHECKING:
from networkx import DiGraph

# Based on the resource names in iac frameworks
AWS_KEYS = ['aws_', 'AWS::', 'aws-']
GCP_KEYS = ['gcloud', 'google_']
AZURE_KEYS = ['azurerm_', 'Microsoft.']


class BaseSolver:
operator = "" # noqa: CCE003 # a static attribute
Expand Down Expand Up @@ -42,21 +47,17 @@ def resource_type_pred(self, v: Dict[str, Any], resource_types: List[str]) -> bo
return not resource_types or (resource_type in v and v[resource_type] in resource_types)

def resource_match_provider(self, resource_type: str) -> bool:
# Based on the resource names in iac frameworks
aws_keys = ['aws_', 'AWS::', 'aws-']
gcp_keys = ['gcloud', 'google_']
azure_keys = ['azurerm_', 'Microsoft.']
if not self.providers:
return True
for provider in self.providers:
if provider.lower() == 'aws':
if any(resource_type.startswith(key) for key in aws_keys):
if any(resource_type.startswith(key) for key in AWS_KEYS):
return True
elif provider.lower() == 'gcp':
if any(resource_type.startswith(key) for key in gcp_keys):
if any(resource_type.startswith(key) for key in GCP_KEYS):
return True
elif provider.lower() == 'azure':
if any(resource_type.startswith(key) for key in azure_keys):
if any(resource_type.startswith(key) for key in AZURE_KEYS):
return True
else: # if we don't have a provider or the provider was not one of the basic providers
return True
Expand Down

0 comments on commit 7dd21af

Please sign in to comment.