Skip to content

Commit b4394e6

Browse files
committed
remove elem name from check
1 parent 1cd5091 commit b4394e6

22 files changed

+66
-66
lines changed

glitch/analysis/rules.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,5 +221,5 @@ def check_comment(self, c: Comment, file: str) -> list[Error]:
221221

222222
class SmellChecker(ABC):
223223
@abstractmethod
224-
def check(self, element, file: str, code = None, elem_name: str = "", elem_value: str = "", au_type = None, parent_name = "") -> list[Error]:
224+
def check(self, element, file: str) -> list[Error]:
225225
pass

glitch/analysis/security.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def check_atomicunit(self, au: AtomicUnit, file: str) -> List[Error]:
147147
break
148148

149149
for checker in self.checkers:
150-
errors += checker.check(au, file, self.code, au.name)
150+
errors += checker.check(au, file, self.code)
151151

152152
if self.__is_http_url(au.name):
153153
errors.append(Error('sec_https', au, file, repr(au)))
@@ -159,7 +159,7 @@ def check_atomicunit(self, au: AtomicUnit, file: str) -> List[Error]:
159159
def check_dependency(self, d: Dependency, file: str) -> List[Error]:
160160
return []
161161

162-
def __check_keyvalue(self, c: CodeElement, name: str,
162+
def __check_keyvalue(self, c: KeyValue, name: str,
163163
value: str, has_variable: bool, file: str, au_type = None, parent_name: str = ""):
164164
errors = []
165165
name = name.strip().lower()
@@ -294,7 +294,7 @@ def get_module_var(c, name: str):
294294
value = var.value
295295

296296
for checker in self.checkers:
297-
errors += checker.check(c, file, self.code, name, value, au_type, parent_name)
297+
errors += checker.check(c, file, self.code, value, au_type, parent_name)
298298

299299
return errors
300300

glitch/analysis/terraform/access_control.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
class TerraformAccessControl(TerraformSmellChecker):
9-
def check(self, element, file: str, code, elem_name: str, elem_value: str = "", au_type = None, parent_name = ""):
9+
def check(self, element, file: str, code, elem_value: str = "", au_type = None, parent_name = ""):
1010
errors = []
1111
if isinstance(element, AtomicUnit):
1212
if (element.type == "resource.aws_api_gateway_method"):
@@ -39,7 +39,7 @@ def check(self, element, file: str, code, elem_name: str, elem_value: str = "",
3939
elif (element.type == "resource.google_sql_database_instance"):
4040
errors += self.check_database_flags(element, file, 'sec_access_control', "cross db ownership chaining", "off")
4141
elif (element.type == "resource.aws_s3_bucket"):
42-
expr = "\${aws_s3_bucket\." + f"{elem_name}\."
42+
expr = "\${aws_s3_bucket\." + f"{element.name}\."
4343
pattern = re.compile(rf"{expr}")
4444
if not self.get_associated_au(code, file, "resource.aws_s3_bucket_public_access_block", "bucket", pattern, [""]):
4545
errors.append(Error('sec_access_control', element, file, repr(element),
@@ -54,7 +54,7 @@ def check(self, element, file: str, code, elem_name: str, elem_value: str = "",
5454

5555
elif isinstance(element, Attribute) or isinstance(element, Variable):
5656
for item in SecurityVisitor._POLICY_KEYWORDS:
57-
if item.lower() == elem_name:
57+
if item.lower() == element.name:
5858
for config in SecurityVisitor._POLICY_ACCESS_CONTROL:
5959
expr = config['keyword'].lower() + "\s*" + config['value'].lower()
6060
pattern = re.compile(rf"{expr}")
@@ -64,20 +64,20 @@ def check(self, element, file: str, code, elem_name: str, elem_value: str = "",
6464
errors.append(Error('sec_access_control', element, file, repr(element)))
6565
break
6666

67-
if (re.search(r"actions\[\d+\]", elem_name) and parent_name == "permissions"
67+
if (re.search(r"actions\[\d+\]", element.name) and parent_name == "permissions"
6868
and au_type == "resource.azurerm_role_definition" and elem_value == "*"):
6969
errors.append(Error('sec_access_control', element, file, repr(element)))
70-
elif (((re.search(r"members\[\d+\]", elem_name) and au_type == "resource.google_storage_bucket_iam_binding")
71-
or (elem_name == "member" and au_type == "resource.google_storage_bucket_iam_member"))
70+
elif (((re.search(r"members\[\d+\]", element.name) and au_type == "resource.google_storage_bucket_iam_binding")
71+
or (element.name == "member" and au_type == "resource.google_storage_bucket_iam_member"))
7272
and (elem_value == "allusers" or elem_value == "allauthenticatedusers")):
7373
errors.append(Error('sec_access_control', element, file, repr(element)))
74-
elif (elem_name == "email" and parent_name == "service_account"
74+
elif (element.name == "email" and parent_name == "service_account"
7575
and au_type == "resource.google_compute_instance"
7676
and re.search(r".-compute@developer.gserviceaccount.com", elem_value)):
7777
errors.append(Error('sec_access_control', element, file, repr(element)))
7878

7979
for config in SecurityVisitor._ACCESS_CONTROL_CONFIGS:
80-
if (elem_name == config['attribute'] and au_type in config['au_type']
80+
if (element.name == config['attribute'] and au_type in config['au_type']
8181
and parent_name in config['parents'] and not element.has_variable
8282
and elem_value.lower() not in config['values']
8383
and config['values'] != [""]):

glitch/analysis/terraform/attached_resource.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
class TerraformAttachedResource(TerraformSmellChecker):
8-
def check(self, element, file: str, code, elem_name: str, elem_value: str = "", au_type = None, parent_name = ""):
8+
def check(self, element, file: str, code, elem_value: str = "", au_type = None, parent_name = ""):
99
errors = []
1010
if isinstance(element, AtomicUnit):
1111
def check_attached_resource(attributes, resource_types):

glitch/analysis/terraform/authentication.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66

77

88
class TerraformAuthentication(TerraformSmellChecker):
9-
def check(self, element, file: str, code, elem_name: str, elem_value: str = "", au_type = None, parent_name = ""):
9+
def check(self, element, file: str, code, elem_value: str = "", au_type = None, parent_name = ""):
1010
errors = []
1111
if isinstance(element, AtomicUnit):
1212
if (element.type == "resource.google_sql_database_instance"):
1313
errors += self.check_database_flags(element, file, 'sec_authentication', "contained database authentication", "off")
1414
elif (element.type == "resource.aws_iam_group"):
15-
expr = "\${aws_iam_group\." + f"{elem_name}\."
15+
expr = "\${aws_iam_group\." + f"{element.name}\."
1616
pattern = re.compile(rf"{expr}")
1717
if not self.get_associated_au(code, file, "resource.aws_iam_group_policy", "group", pattern, [""]):
1818
errors.append(Error('sec_authentication', element, file, repr(element),
@@ -27,7 +27,7 @@ def check(self, element, file: str, code, elem_name: str, elem_value: str = "",
2727

2828
elif isinstance(element, Attribute) or isinstance(element, Variable):
2929
for item in SecurityVisitor._POLICY_KEYWORDS:
30-
if item.lower() == elem_name:
30+
if item.lower() == element.name:
3131
for config in SecurityVisitor._POLICY_AUTHENTICATION:
3232
if au_type in config['au_type']:
3333
expr = config['keyword'].lower() + "\s*" + config['value'].lower()
@@ -36,7 +36,7 @@ def check(self, element, file: str, code, elem_name: str, elem_value: str = "",
3636
errors.append(Error('sec_authentication', element, file, repr(element)))
3737

3838
for config in SecurityVisitor._AUTHENTICATION:
39-
if (elem_name == config['attribute'] and au_type in config['au_type']
39+
if (element.name == config['attribute'] and au_type in config['au_type']
4040
and parent_name in config['parents'] and not element.has_variable
4141
and elem_value.lower() not in config['values']
4242
and config['values'] != [""]):

glitch/analysis/terraform/dns_policy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
class TerraformDnsWithoutDnssec(TerraformSmellChecker):
8-
def check(self, element, file: str, code, elem_name: str, elem_value: str = "", au_type = None, parent_name = ""):
8+
def check(self, element, file: str, code, elem_value: str = "", au_type = None, parent_name = ""):
99
errors = []
1010
if isinstance(element, AtomicUnit):
1111
for config in SecurityVisitor._DNSSEC_CONFIGS:
@@ -16,7 +16,7 @@ def check(self, element, file: str, code, elem_name: str, elem_value: str = "",
1616

1717
elif isinstance(element, Attribute) or isinstance(element, Variable):
1818
for config in SecurityVisitor._DNSSEC_CONFIGS:
19-
if (elem_name == config['attribute'] and au_type in config['au_type']
19+
if (element.name == config['attribute'] and au_type in config['au_type']
2020
and parent_name in config['parents'] and not element.has_variable
2121
and elem_value.lower() not in config['values']
2222
and config['values'] != [""]):

glitch/analysis/terraform/firewall_misconfig.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
class TerraformFirewallMisconfig(TerraformSmellChecker):
8-
def check(self, element, file: str, code, elem_name: str, elem_value: str = "", au_type = None, parent_name = ""):
8+
def check(self, element, file: str, code, elem_value: str = "", au_type = None, parent_name = ""):
99
errors = []
1010
if isinstance(element, AtomicUnit):
1111
for config in SecurityVisitor._FIREWALL_CONFIGS:
@@ -16,7 +16,7 @@ def check(self, element, file: str, code, elem_name: str, elem_value: str = "",
1616

1717
elif isinstance(element, Attribute) or isinstance(element, Variable):
1818
for config in SecurityVisitor._FIREWALL_CONFIGS:
19-
if (elem_name == config['attribute'] and au_type in config['au_type']
19+
if (element.name == config['attribute'] and au_type in config['au_type']
2020
and parent_name in config['parents'] and config['values'] != [""]):
2121
if ("any_not_empty" in config['values'] and elem_value.lower() == ""):
2222
return [Error('sec_firewall_misconfig', element, file, repr(element))]

glitch/analysis/terraform/http_without_tls.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
class TerraformHttpWithoutTls(TerraformSmellChecker):
8-
def check(self, element, file: str, code, elem_name: str, elem_value: str = "", au_type = None, parent_name = ""):
8+
def check(self, element, file: str, code, elem_value: str = "", au_type = None, parent_name = ""):
99
errors = []
1010
if isinstance(element, AtomicUnit):
1111
if (element.type == "data.http"):
@@ -36,7 +36,7 @@ def check(self, element, file: str, code, elem_name: str, elem_value: str = "",
3636

3737
elif isinstance(element, Attribute) or isinstance(element, Variable):
3838
for config in SecurityVisitor._HTTPS_CONFIGS:
39-
if (elem_name == config["attribute"] and au_type in config["au_type"]
39+
if (element.name == config["attribute"] and au_type in config["au_type"]
4040
and parent_name in config["parents"] and not element.has_variable
4141
and elem_value.lower() not in config["values"]):
4242
return [Error('sec_https', element, file, repr(element))]

glitch/analysis/terraform/integrity_policy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
class TerraformIntegrityPolicy(TerraformSmellChecker):
8-
def check(self, element, file: str, code, elem_name: str, elem_value: str = "", au_type = None, parent_name = ""):
8+
def check(self, element, file: str, code, elem_value: str = "", au_type = None, parent_name = ""):
99
errors = []
1010
if isinstance(element, AtomicUnit):
1111
for policy in SecurityVisitor._INTEGRITY_POLICY:
@@ -15,7 +15,7 @@ def check(self, element, file: str, code, elem_name: str, elem_value: str = "",
1515
f"Suggestion: check for a required attribute with name '{policy['msg']}'."))
1616
elif isinstance(element, Attribute) or isinstance(element, Variable):
1717
for policy in SecurityVisitor._INTEGRITY_POLICY:
18-
if (elem_name == policy['attribute'] and au_type in policy['au_type']
18+
if (element.name == policy['attribute'] and au_type in policy['au_type']
1919
and parent_name in policy['parents'] and not element.has_variable
2020
and elem_value.lower() not in policy['values']):
2121
return[Error('sec_integrity_policy', element, file, repr(element))]

glitch/analysis/terraform/key_management.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77

88
class TerraformKeyManagement(TerraformSmellChecker):
9-
def check(self, element, file: str, code, elem_name: str, elem_value: str = "", au_type = None, parent_name = ""):
9+
def check(self, element, file: str, code, elem_value: str = "", au_type = None, parent_name = ""):
1010
errors = []
1111
if isinstance(element, AtomicUnit):
1212
if (element.type == "resource.azurerm_storage_account"):
13-
expr = "\${azurerm_storage_account\." + f"{elem_name}\."
13+
expr = "\${azurerm_storage_account\." + f"{element.name}\."
1414
pattern = re.compile(rf"{expr}")
1515
if not self.get_associated_au(code, file, "resource.azurerm_storage_account_customer_managed_key", "storage_account_id",
1616
pattern, [""]):
@@ -25,7 +25,7 @@ def check(self, element, file: str, code, elem_name: str, elem_value: str = "",
2525

2626
elif isinstance(element, Attribute) or isinstance(element, Variable):
2727
for config in SecurityVisitor._KEY_MANAGEMENT:
28-
if (elem_name == config['attribute'] and au_type in config['au_type']
28+
if (element.name == config['attribute'] and au_type in config['au_type']
2929
and parent_name in config['parents'] and config['values'] != [""]):
3030
if ("any_not_empty" in config['values'] and elem_value.lower() == ""):
3131
errors.append(Error('sec_key_management', element, file, repr(element)))
@@ -35,15 +35,15 @@ def check(self, element, file: str, code, elem_name: str, elem_value: str = "",
3535
errors.append(Error('sec_key_management', element, file, repr(element)))
3636
break
3737

38-
if (elem_name == "rotation_period" and au_type == "resource.google_kms_crypto_key"):
38+
if (element.name == "rotation_period" and au_type == "resource.google_kms_crypto_key"):
3939
expr1 = r'\d+\.\d{0,9}s'
4040
expr2 = r'\d+s'
4141
if (re.search(expr1, elem_value) or re.search(expr2, elem_value)):
4242
if (int(elem_value.split("s")[0]) > 7776000):
4343
errors.append(Error('sec_key_management', element, file, repr(element)))
4444
else:
4545
errors.append(Error('sec_key_management', element, file, repr(element)))
46-
elif (elem_name == "kms_master_key_id" and ((au_type == "resource.aws_sqs_queue"
46+
elif (element.name == "kms_master_key_id" and ((au_type == "resource.aws_sqs_queue"
4747
and elem_value == "alias/aws/sqs") or (au_type == "resource.aws_sns_queue"
4848
and elem_value == "alias/aws/sns"))):
4949
errors.append(Error('sec_key_management', element, file, repr(element)))

0 commit comments

Comments
 (0)