Skip to content

Commit

Permalink
fix integration test3
Browse files Browse the repository at this point in the history
  • Loading branch information
chanaMovshowich committed Jun 9, 2024
1 parent 1fe6d9f commit cb7e4a5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/common/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ var mutex sync.Mutex

func AppendSkipedByCommentToRunnerSkippedResources(skippedResources *[]string) {
mutex.Lock()
defer mutex.Unlock()

*skippedResources = append(*skippedResources, SkipResourcesByComment...)
SkipResourcesByComment = SkipResourcesByComment[:0]
mutex.Unlock()
}

func InSlice[T comparable](elems []T, v T) bool {
Expand Down
6 changes: 6 additions & 0 deletions src/common/yaml/yaml_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"regexp"
"sort"
"strings"
"sync"

Check failure on line 10 in src/common/yaml/yaml_writer.go

View workflow job for this annotation

GitHub Actions / golangci-lint

[golangci-lint] reported by reviewdog 🐶 File is not `gofmt`-ed with `-s` (gofmt) Raw Output: src/common/yaml/yaml_writer.go:10: File is not `gofmt`-ed with `-s` (gofmt) "sync"

"github.com/bridgecrewio/yor/src/common/logger"
"github.com/bridgecrewio/yor/src/common/structure"
Expand All @@ -16,6 +17,7 @@ import (
)

const SingleIndent = " "
var mutex sync.Mutex

func WriteYAMLFile(readFilePath string, blocks []structure.IBlock, writeFilePath string, tagsAttributeName string, resourcesStartToken string) error {
// #nosec G304
Expand Down Expand Up @@ -288,7 +290,9 @@ func MapResourcesLineYAML(filePath string, resourceNames []string, resourcesStar
cleanContent := strings.TrimSpace(line)
if strings.HasPrefix(cleanContent, resourcesStartToken+":") {
if strings.ToUpper(strings.TrimSpace(fileLines[i-1])) == "#YOR:SKIPALL" {
mutex.Lock()
utils.SkipResourcesByComment = append(utils.SkipResourcesByComment, resourceNames...)
mutex.Unlock()
}
readResources = true
resourcesIndent = countLeadingSpaces(line)
Expand All @@ -298,7 +302,9 @@ func MapResourcesLineYAML(filePath string, resourceNames []string, resourcesStar
if readResources {
if i > 0 {
if strings.ToUpper(strings.TrimSpace(fileLines[i-1])) == "#YOR:SKIP" {
mutex.Lock()
utils.SkipResourcesByComment = append(utils.SkipResourcesByComment, strings.Trim(strings.TrimSpace(line), ":"))
mutex.Unlock()
}
}
lineIndent := countLeadingSpaces(line)
Expand Down
3 changes: 3 additions & 0 deletions src/terraform/structure/terraform_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
)

var ignoredDirs = []string{".git", ".DS_Store", ".idea", ".terraform"}
var mutex sync.Mutex
var unsupportedTerraformBlocks = []string{
"aws_autoscaling_group", // This resource specifically supports tags with a different structure, see: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/autoscaling_group#tag-and-tags
"aws_lb_listener", // This resource does not support tags, although docs state otherwise.
Expand Down Expand Up @@ -184,7 +185,9 @@ func (p *TerraformParser) ParseFile(filePath string) ([]structure.IBlock, error)
}

if strings.ToUpper(strings.TrimSpace(lineAbove)) == "#YOR:SKIP" || skipAll {
mutex.Lock()
utils.SkipResourcesByComment = append(utils.SkipResourcesByComment, terraformBlock.GetResourceID())
mutex.Unlock()
}
}
parsedBlocks = append(parsedBlocks, terraformBlock)
Expand Down

0 comments on commit cb7e4a5

Please sign in to comment.