Skip to content

fix(query): removed unnecessary else on get_children helper function from sql server database with unrecommended retention days query#7705

Merged
cx-ricardo-jesus merged 9 commits into
masterfrom
AST-40746
Sep 9, 2025
Merged

fix(query): removed unnecessary else on get_children helper function from sql server database with unrecommended retention days query#7705
cx-ricardo-jesus merged 9 commits into
masterfrom
AST-40746

Conversation

@cx-ricardo-jesus

Copy link
Copy Markdown
Contributor

Closes #

Reason for Proposed Changes

  • On the current implementation, the helper function get_children does not use the second else case on any scenario:
get_children(doc, parent, path) = childArr { 
	common_lib.valid_key(parent, "resources")
    childArr := [{"value": parent.resources, "path": array.concat(path, ["resources"])}]
} else = childArr { 
    not common_lib.valid_key(parent, "resources")
    not common_lib.valid_key(parent, "dependsOn")
	values := [x |
    	[path_child, value_child] := walk(doc)
        value_child.name != parent.name
        not common_lib.valid_key(value_child, "dependsOn")
		startswith(value_child.name, parent.name)
        x := {"value": [value_child], "path": path_child}
    ]
	count(values) > 0
    unique := {y | y := values[_]} 
    childArr := [y | y := unique[_]]
} else = childArr {
	not common_lib.valid_key(parent, "resources")
	values := [x | 
		[path_child, value_child] := walk(doc)
		value_child.name != parent.name
		common_lib.valid_key(value_child, "dependsOn")
		d := value_child.dependsOn[_]
		search_values := {"type": parent.type, "name": parent.name}
		contains(d, search_values.type)
		contains(d, search_values.name)
		x := {"value": [value_child], "path": path_child}
	]
	count(values) > 0
	unique := {y | y := values[_]}
	childArr := [y | y := unique[_]]
}

Proposed Changes

  • Removed the second else from the helper function and added an get_searchLine helper function in order to obtain the correct value for the searchLine.
  • Added one negative case on the test cases (negative4.bicep and negative4.json), when the state from the auditingSetting is not enabled.
  • Added one positive case on the test cases (positive7.bicep and positive7.json) that do not have the keyword dependsOn, the refer to a parent resource.

I submit this contribution under the Apache-2.0 license.

@cx-ricardo-jesus cx-ricardo-jesus requested a review from a team as a code owner September 8, 2025 10:45
@github-actions github-actions Bot added the query New query feature label Sep 8, 2025
@github-actions

github-actions Bot commented Sep 8, 2025

Copy link
Copy Markdown
Contributor

kics-logo

KICS version: v2.1.11

Category Results
CRITICAL CRITICAL 0
HIGH HIGH 0
MEDIUM MEDIUM 0
LOW LOW 0
INFO INFO 0
TRACE TRACE 0
TOTAL TOTAL 0
Metric Values
Files scanned placeholder 1
Files parsed placeholder 1
Files failed to scan placeholder 0
Total executed queries placeholder 47
Queries failed to execute placeholder 0
Execution time placeholder 0

@cx-artur-ribeiro cx-artur-ribeiro left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@cx-ricardo-jesus cx-ricardo-jesus merged commit c5217ae into master Sep 9, 2025
26 checks passed
@cx-ricardo-jesus cx-ricardo-jesus deleted the AST-40746 branch September 9, 2025 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

query New query feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants