Skip to content

Commit

Permalink
Merge branch 'master' into AST-45283-ARM
Browse files Browse the repository at this point in the history
  • Loading branch information
cx-ruiaraujo authored Jul 22, 2024
2 parents abdabc6 + ab1c0cf commit b3c8f6f
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 25 deletions.
Binary file modified .github/scripts/queries-validator/requirements.txt
Binary file not shown.
2 changes: 1 addition & 1 deletion assets/libraries/azureresourcemanager.rego
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ getDefaultValueFromParametersIfPresent(doc, valueToCheck) = [value, propertyType
isParameterReference(valueToCheck) = parameterName {
startswith(valueToCheck, "[parameters('")
endswith(valueToCheck, "')]")
parameterName := trim_right(trim_left(valueToCheck, "[parameters('"),"')]")
parameterName := trim_right(trim_left(trim_left(valueToCheck, "[parameters"), "('"), "')]")
}


Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ require (
golang.org/x/sys v0.21.0 // indirect
golang.org/x/term v0.21.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/grpc v1.64.0 // indirect
google.golang.org/grpc v1.64.1 // indirect
google.golang.org/protobuf v1.34.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1421,8 +1421,8 @@ google.golang.org/grpc v1.48.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACu
google.golang.org/grpc v1.49.0/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI=
google.golang.org/grpc v1.50.0/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI=
google.golang.org/grpc v1.50.1/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI=
google.golang.org/grpc v1.64.0 h1:KH3VH9y/MgNQg1dE7b3XfVK0GsPSIzJwdF617gUSbvY=
google.golang.org/grpc v1.64.0/go.mod h1:oxjF8E3FBnjp+/gVFYdWacaLDx9na1aqy9oovLpxQYg=
google.golang.org/grpc v1.64.1 h1:LKtvyfbX3UGVPFcGqJ9ItpVWW6oN/2XqTxfAnwRRXiA=
google.golang.org/grpc v1.64.1/go.mod h1:hiQF4LFZelK2WKaP6W0L92zGHtiQdZxk8CrSdvyjeP0=
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
Expand Down
45 changes: 24 additions & 21 deletions pkg/resolver/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,15 +450,16 @@ func (r *Resolver) resolvePath(
return obj, false
}
}
return r.resolvePathReturnValue(value, filePath, splitPath, sameFileResolve, originalFileContent, obj)
return r.resolvePathReturnValue(value, filePath, splitPath, sameFileResolve, originalFileContent, obj, maxResolverDepth)
}

func (r *Resolver) resolvePathReturnValue(
value, filePath string,
splitPath []string,
sameFileResolve bool,
originalFileContent []byte,
obj any) (any, bool) {
obj any,
maxResolverDepth int) (any, bool) {
if len(splitPath) > 1 {
if sameFileResolve {
r.ResolvedFiles[filePath] = model.ResolvedFile{
Expand All @@ -469,7 +470,7 @@ func (r *Resolver) resolvePathReturnValue(
}
section, err := findSection(obj, splitPath[1])
// Check if there was an error finding the section or if the reference is circular
if err != nil || checkIfCircular(value, section) {
if err != nil || checkIfCircular(value, section, maxResolverDepth) {
return value, false
}
if sectionMap, ok := section.(map[string]interface{}); ok {
Expand Down Expand Up @@ -537,25 +538,27 @@ func findSection(object interface{}, sectionsString string) (interface{}, error)
return object, nil
}

func checkIfCircular(circularValue string, section interface{}) bool {
sectionAsMap, okMap := section.(map[string]interface{})
sectionAsList, okList := section.([]interface{})
if !okList && !okMap {
return false
}
if okMap {
for key, val := range sectionAsMap {
// if there is a reference to the same value that was resolved it is a circular definition
if key == "$ref" && val == circularValue {
return true
} else if checkIfCircular(circularValue, val) {
return true
}
func checkIfCircular(circularValue string, section interface{}, maxResolverDepth int) bool {
if maxResolverDepth > 0 {
sectionAsMap, okMap := section.(map[string]interface{})
sectionAsList, okList := section.([]interface{})
if !okList && !okMap {
return false
}
} else {
for _, listSection := range sectionAsList {
if checkIfCircular(circularValue, listSection) {
return true
if okMap {
for key, val := range sectionAsMap {
// if there is a reference to the same value that was resolved it is a circular definition
if key == "$ref" && val == circularValue {
return true
} else if checkIfCircular(circularValue, val, maxResolverDepth-1) {
return true
}
}
} else {
for _, listSection := range sectionAsList {
if checkIfCircular(circularValue, listSection, maxResolverDepth-1) {
return true
}
}
}
}
Expand Down

0 comments on commit b3c8f6f

Please sign in to comment.