Skip to content

Commit

Permalink
Fix git modifier tag (#29)
Browse files Browse the repository at this point in the history
* make modifying users a set to prevent repetition of the same modifier

* fixed linter errors
  • Loading branch information
rotemavni authored Feb 18, 2021
1 parent 1ffab4c commit e599f64
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
6 changes: 5 additions & 1 deletion common/tagging/tags/git_modifiers.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ func (t *GitModifiersTag) CalculateValue(data interface{}) error {
if !ok {
return fmt.Errorf("failed to convert data to *GitBlame, which is required to calculte tag value. Type of data: %s", reflect.TypeOf(data))
}
foundModifyingUsers := make(map[string]bool)
var modifyingUsers []string
for _, v := range gitBlame.BlamesByLine {
userName := strings.Split(v.Author, "@")[0]
modifyingUsers = append(modifyingUsers, userName)
if !foundModifyingUsers[userName] {
modifyingUsers = append(modifyingUsers, userName)
foundModifyingUsers[userName] = true
}
}

sort.Strings(modifyingUsers)
Expand Down
13 changes: 7 additions & 6 deletions terraform/structure/terraform_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@ import (
"bridgecrewio/yor/common/structure"
"bridgecrewio/yor/common/tagging/tags"
"fmt"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/hcl/v2"
"github.com/hashicorp/hcl/v2/hclsyntax"
"github.com/hashicorp/hcl/v2/hclwrite"
"github.com/minamijoyo/tfschema/tfschema"
"github.com/zclconf/go-cty/cty"
"io/ioutil"
"os"
"path/filepath"
"reflect"
"strconv"
"strings"

"github.com/hashicorp/go-hclog"
"github.com/hashicorp/hcl/v2"
"github.com/hashicorp/hcl/v2/hclsyntax"
"github.com/hashicorp/hcl/v2/hclwrite"
"github.com/minamijoyo/tfschema/tfschema"
"github.com/zclconf/go-cty/cty"
)

var prefixToTagAttribute = map[string]string{"aws": "tags", "azure": "tags", "gcp": "labels"}
Expand Down
6 changes: 6 additions & 0 deletions tests/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ func SetupBlame(t *testing.T) gitservice.GitBlame {
Date: secondCommitDate,
Hash: plumbing.NewHash(CommitHash2),
},
2: {
Author: "jonjozwiak@users.noreply.github.com",
Text: "Bridgecrew solution to create vulnerable infrastructure",
Date: secondCommitDate,
Hash: plumbing.NewHash(CommitHash2),
},
},
}
}
Expand Down

0 comments on commit e599f64

Please sign in to comment.