Examples can be found in tests/yor_plugins
Yor supports 2 ways of adding custom tags:
- Simple tags with constant key-value
- Simple code-based tags
- Complex tags which rely on different inputs
To add tags with constant key-value pairs, set the environment variable YOR_SIMPLE_TAGS with a JSON object detailing all key value pairs. Example:
export YOR_SIMPLE_TAGS='{"somekey": "somevalue", "another-key": "another_val"}'
# When yor is run, all resources will be tagged by these two tags as well
- Create tags implementing the
ITag
interface. - If you wish to override an existing tag, make the tag's method
GetPriority()
return a positive number. Otherwise, return0
or a negative number. - Create a file located in package
main
that exposes a variableExtraTags
- array containing pointers to all tags implemented. Example:package main var ExtraTags = []interface{}{&TerragoatTag{}, &CheckovTag{}}
- Run the command
go build -gcflags="all=-N -l" -buildmode=plugin -o <plugin-dir>/extra_tags.so <plugin-dir>/*.go
See example in tests/yor_plugins/example
- Create a tagger struct, implementing the
ITagger
interface. - Implement the
InitTagger
method, which should look something like this:func (d *CustomTagger) InitTagger(_ string, skippedTags []string) { d.SkippedTags = skippedTags d.SetTags([]tags.ITag{}) // This is just a placeholder }
- Implement the
CreateTagsForBlock
method, which will look something like this:func (d *CustomTagger) CreateTagsForBlock(block structure.IBlock) { var newTags []tags.ITag for _, tag := range d.GetTags() { tagVal, err := tag.CalculateValue(<Whichever struct you choose to pass to the tagger>) if err != nil { logger.Error(fmt.Sprintf("Failed to create %v tag for block %v", tag.GetKey(), block.GetResourceID())) } newTags = append(newTags, tagVal) } block.AddNewTags(newTags) }
- Implement tags, which implement the
ITag
interface just like we described here - Go back to the
InitTagger
method and add pointers to your new tags in the input of theSetTags
function call. - Create a file located in package
main
that exposes a variableExtraTaggers
- array containing pointers to all tags implemented. Example:package main var ExtraTaggers = []interface{}{&CustomTagger{}}
See example in tests/yor_plugins/tag_group_example
./yor tag --custom-tagging tests/yor_plugins/example
# run yor with custom tags located in tests/yor_plugins/example
./yor tag --custom-tagging tests/yor_plugins/example,tests/yor_plugins/tag_group_example
# run yor with custom tags located in tests/yor_plugins/example and custom taggers located in tests/yor_plugins/tag_group_example