-
Notifications
You must be signed in to change notification settings - Fork 120
/
tag_group.go
54 lines (48 loc) · 1.49 KB
/
tag_group.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package simple
import (
"encoding/json"
"fmt"
"os"
"strings"
"github.com/bridgecrewio/yor/src/common/logger"
"github.com/bridgecrewio/yor/src/common/structure"
"github.com/bridgecrewio/yor/src/common/tagging"
"github.com/bridgecrewio/yor/src/common/tagging/tags"
)
type TagGroup struct {
tagging.TagGroup
}
func (t *TagGroup) InitTagGroup(_ string, skippedTags []string, explicitlySpecifiedTags []string, options ...tagging.InitTagGroupOption) {
t.SkippedTags = skippedTags
t.SpecifiedTags = explicitlySpecifiedTags
envTagsStr := os.Getenv("YOR_SIMPLE_TAGS")
if envTagsStr == "" {
return
}
logger.Debug(fmt.Sprintf("Simple tags from env: %v", envTagsStr))
var extraTagsFromArgs map[string]string
if strings.HasPrefix(envTagsStr, "'") {
envTagsStr = envTagsStr[1 : len(envTagsStr)-1]
}
if strings.HasPrefix(envTagsStr, "\"") {
err := json.Unmarshal([]byte(envTagsStr), &envTagsStr)
if err != nil {
logger.Info(fmt.Sprintf("failed to parse extra tags from env: %s", err))
}
}
if err := json.Unmarshal([]byte(envTagsStr), &extraTagsFromArgs); err != nil {
logger.Info(fmt.Sprintf("failed to parse extra tags from env: %s", err))
} else {
var envTags []tags.ITag
for key, value := range extraTagsFromArgs {
envTags = append(envTags, tags.Init(key, value))
}
t.SetTags(envTags)
}
}
func (t *TagGroup) GetDefaultTags() []tags.ITag {
return []tags.ITag{}
}
func (t *TagGroup) CreateTagsForBlock(block structure.IBlock) error {
return t.UpdateBlockTags(block, struct{}{})
}