bridgecrewio / yor

Extensible auto-tagger for your IaC files. The ultimate way to link entities in the cloud back to the codified resource which created it.
https://www.yor.io
Apache License 2.0
810 stars 123 forks source link

Custom tagger replacing key and value if they are the same #277

Closed jdorsman-bhvr closed 1 year ago

jdorsman-bhvr commented 2 years ago

Describe the bug Upon using a custom tagger defined with the YAML format, I noticed that if you use placeholders as defaults that are the same value as the key name, changing the value also overrides the key name. It appears that the find/replace logic is too loose.

To Reproduce

  1. Create a custom tagger in YAML format like this:
tag_groups:
  - name: tagger-test
    tags:
      - name: project
        value:
          default: project
      - name: environment
        value:
          default: environment
  1. Run the custom tagger, like: yor tag --config-file custom_tagger.yaml --skip-tags 'yor_trace,git*' -d .
  2. Observe the created file, which looks correct/as expected (terraform example below):
  tags = {
    environment = "environment"
    project     = "project"
  }
  1. Change the placeholders in the custom tagger to actual values, like:
tag_groups:
  - name: tagger-test
    tags:
      - name: project
        value:
          default: foo
      - name: environment
        value:
          default: dev
  1. Run the custom tagger a second time, like yor tag --config-file custom_tagger.yaml --skip-tags 'yor_trace,git*' -d .
  2. Observe the CLI output, which appears correct (also see screenshot below).
  3. Observe how the tag keys have been adjusted, just like the values:
  tags = {
    dev = "dev"
    foo = "foo"
  }

Expected behavior Only the values for the tags should have been overwritten, not the keys:

  tags = {
    environment = "dev"
    project     = "foo"
  }

Screenshots image The CLI output seems correct, only the value should have been updated, the tag key should have been unchanged.

Desktop (please complete the following information):

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.