From afb6930992e7c22b128b377ce0fd46fef9e1d1a8 Mon Sep 17 00:00:00 2001 From: Scott Piper <0xdabbad00@users.noreply.github.com> Date: Thu, 20 Aug 2020 15:30:10 -0600 Subject: [PATCH] Location fixes (#143) * Fixed location statement * Fix malformed json location * Bump version --- parliament/__init__.py | 4 ++-- parliament/statement.py | 9 ++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/parliament/__init__.py b/parliament/__init__.py index ca9c757..0ebe560 100644 --- a/parliament/__init__.py +++ b/parliament/__init__.py @@ -1,7 +1,7 @@ """ This library is a linter for AWS IAM policies. """ -__version__ = "1.1.0" +__version__ = "1.2.0" import fnmatch import functools @@ -62,7 +62,7 @@ def analyze_policy_string( policy_json = jsoncfg.loads_config(policy_str) except jsoncfg.parser.JSONConfigParserException as e: policy = Policy(None) - policy.add_finding("MALFORMED_JSON", detail="json parsing error: {}".format(e)) + policy.add_finding("MALFORMED_JSON", detail="json parsing error: {}".format(e), location={'line': e.line, 'column': e.column}) return policy policy = Policy(policy_json, filepath, config) diff --git a/parliament/statement.py b/parliament/statement.py index d4464b4..0cc0654 100644 --- a/parliament/statement.py +++ b/parliament/statement.py @@ -383,7 +383,6 @@ def add_finding(self, finding, detail=None, location={}): location: Dictionary with information about where this problem is. Often set to: {"location": "string"} """ - if "jsoncfg.config_classes.ConfigJSONObject" in str(type(location)): node_location = jsoncfg.node_location(location) location = {"line": node_location.line, "column": node_location.column} @@ -577,7 +576,7 @@ def _check_condition(self, operator, condition_block, expanded_actions): detail="Unknown condition {} for action {}:{}".format( key, action_struct["service"], action_struct["action"] ), - location={"location": condition_block}, + location=condition_block, ) continue @@ -601,7 +600,7 @@ def _check_condition(self, operator, condition_block, expanded_actions): detail="Type mismatch: {} requires a value of type {} but given {}".format( key, condition_type, values ), - location={"location": condition_block}, + location=condition_block, ) if condition_type is not None: @@ -623,7 +622,7 @@ def _check_condition(self, operator, condition_block, expanded_actions): operator_type_requirement, translate_documentation_types(condition_type), ), - location={"location": condition_block}, + location=condition_block, ) else: self.add_finding( @@ -633,7 +632,7 @@ def _check_condition(self, operator, condition_block, expanded_actions): operator_type_requirement, translate_documentation_types(condition_type), ), - location={"location": condition_block}, + location=condition_block, ) return