Skip to content

Commit

Permalink
Location fixes (#143)
Browse files Browse the repository at this point in the history
* Fixed location statement

* Fix malformed json location

* Bump version
  • Loading branch information
0xdabbad00 committed Aug 20, 2020
1 parent 4570824 commit afb6930
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
4 changes: 2 additions & 2 deletions parliament/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 4 additions & 5 deletions parliament/statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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

Expand All @@ -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:
Expand All @@ -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(
Expand All @@ -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
Expand Down

0 comments on commit afb6930

Please sign in to comment.