src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Security/Checks/sshNoHostKeyVerification.py

branch
eric7
changeset 10507
d1c6608155ef
parent 10439
21c28b0f9e41
child 10638
12558008c269
--- a/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Security/Checks/sshNoHostKeyVerification.py	Tue Jan 16 14:35:46 2024 +0100
+++ b/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Security/Checks/sshNoHostKeyVerification.py	Tue Jan 16 18:24:06 2024 +0100
@@ -15,6 +15,8 @@
 # SPDX-License-Identifier: Apache-2.0
 #
 
+import ast
+
 
 def getChecks():
     """
@@ -45,13 +47,21 @@
     if (
         context.isModuleImportedLike("paramiko")
         and context.callFunctionName == "set_missing_host_key_policy"
-        and context.callArgs
-        and context.callArgs[0] in ["AutoAddPolicy", "WarningPolicy"]
+        and context.node.args
     ):
-        reportError(
-            context.node.lineno - 1,
-            context.node.col_offset,
-            "S507",
-            "H",
-            "M",
-        )
+        policyArgument = context.node.args[0]
+
+        policyArgumentValue = None
+        if isinstance(policyArgument, ast.Attribute):
+            policyArgumentValue = policyArgument.attr
+        elif isinstance(policyArgument, ast.Call):
+            policyArgumentValue = policyArgument.func.attr
+
+        if policyArgumentValue in ["AutoAddPolicy", "WarningPolicy"]:
+            reportError(
+                context.node.lineno - 1,
+                context.node.col_offset,
+                "S507",
+                "H",
+                "M",
+            )

eric ide

mercurial