Skip to content

Commit

Permalink
update readme n fn
Browse files Browse the repository at this point in the history
Signed-off-by: Sumit Jaiswal <[email protected]>
  • Loading branch information
justjais committed Jun 22, 2024
1 parent 140ba1b commit cb53daf
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,17 @@ $ ari ram generate -f ram_input_list.txt

```

## ARI supported options to run against

Name | Description
--- | ---
playbook | Scan a playbook (e.g. `ari playbook path/to/playbook.yml` )
collection | Scan a collection (e.g. `ari collection collection.name` )
role | Scan a role (e.g. `ari role role.name` )
project | Scan a project (e.g. `ari project path/to/project`)
taskfile | Scan a taskfile (e.g. `ari taskfile path/to/taskfile.yml`)
ram | Operate the backend data (e.g. `ari ram generate -f input.txt`)

## Installation (for development)

```
Expand Down
30 changes: 21 additions & 9 deletions ansible_risk_insight/finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ def list_scan_target(root_dir: str, task_num_threshold: int = -1):
return all_targets


def update_line_logic(new_line_content, old_line_content, leading_spaces=0):
def update_line_with_space(new_line_content, old_line_content, leading_spaces=0):
"""
Returns the line of the input lines with mutation, having spaces
exactly same as input yaml lines
Expand Down Expand Up @@ -777,6 +777,10 @@ def check_and_add_diff_lines(start_line, stop_line, lines, data_copy):


def check_diff_and_copy_olddata_to_newdata(line_number_list, lines, new_data):
"""
Function to find the old lines which weren't mutated by ARI rules,
it need to be copied to new content as is
"""
if line_number_list and isinstance(line_number_list, list):
new_content_last_set = line_number_list[-1]
new_content_last_line = int(new_content_last_set.lstrip("L").split("-")[1])
Expand All @@ -786,6 +790,16 @@ def check_diff_and_copy_olddata_to_newdata(line_number_list, lines, new_data):
return new_data


def update_and_append_new_line(new_line, old_line, leading_spaces, data_copy):
"""
Function to get the leading space for the new ARI mutated line, with
its equivaltent old line with space similar to the old line
"""
line_with_adjusted_space = update_line_with_space(new_line, old_line, leading_spaces)
data_copy.append(line_with_adjusted_space)
return ''


def update_the_yaml_target(file_path, line_number_list, new_content_list):
try:
# Read the original YAML file
Expand Down Expand Up @@ -860,21 +874,19 @@ def update_the_yaml_target(file_path, line_number_list, new_content_list):
lines.pop(i)
else:
break
lines[k] = update_line_logic(new_line_content, lines[k], leading_spaces)
data_copy.append(lines[k])
new_line_content = update_and_append_new_line(new_line_content, lines[k], 0, data_copy)
break
elif old_key == new_key:
lines[k] = update_line_logic(new_line_content, lines[k])
data_copy.append(lines[k])
new_line_content = update_and_append_new_line(new_line_content, lines[k], 0, data_copy)
break
elif old_key.rstrip('\n') == new_key:
lines[k] = update_line_logic(new_line_content, lines[k])
data_copy.append(lines[k])
new_line_content = update_and_append_new_line(new_line_content, lines[k], 0, data_copy)
break
elif old_key.rstrip('\n') in new_key.split('.'):
lines[k] = update_line_logic(new_line_content, lines[k])
data_copy.append(lines[k])
new_line_content = update_and_append_new_line(new_line_content, lines[k], 0, data_copy)
break
if new_line_content: # if there wasn't a match with old line, so this seems updated by ARI and added to w/o any change
data_copy.append(new_line_content)
else:
return IndexError("Line number out of range.")
# check for diff b/w new content and old contents,
Expand Down

0 comments on commit cb53daf

Please sign in to comment.