Skip to content

Conversation

migmartri
Copy link
Member

@migmartri migmartri commented Jul 30, 2023

Enables annotations interpolation (#252) in the Dependency-Track plugin.

Now, during attachment, the project name can contain material annotations that will be resolved before pushing to the dep-track instance.

For example, let's say that you have the following contract with two SBOMs and a component annotation (note that the value of the annotation is set in the contract but it is also now possible to set it at runtime #281)

{
  "schemaVersion":  "v1",
  "materials":  [
    {
      "type":  "SBOM_CYCLONEDX_JSON",
      "name":  "controlplane-sbom",
      "annotations":  [
        {
          "name":  "component",
          "value":  "controlplane"
        }
      ]
    },
    {
      "type":  "SBOM_CYCLONEDX_JSON",
      "name":  "cas-sbom",
      "annotations":  [
        {
          "name":  "component",
          "value":  "cas"
        }
      ]
    }
  ]
}

This annotation can then be set during attachment.

chainloop integration attached add ... --opt projectName="miguel-test-{{.Material.Annotations.component}}

The result of this at execution time would be sending

  • controlplane-sbom => miguel-test-controlplane
  • cas-sbom => miguel-test-cas

image

Some notes about the implementation

  • Adding templates in the project name is optional, using static names is also supported (current behavior)
  • At attachment time we check if the template in the project name is valid
  • At execution time, if we can't find the annotation in one of the SBOMs, we skip it.

Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev>
@migmartri migmartri requested a review from danlishka July 30, 2023 15:38
// We currently support the following template variables:
// - material.annotations.<key>
// For example, project-name => {{ material.annotations.my_annotation }}
func resolveProjectName(projectNameTpl string, annotations map[string]string) (string, error) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the new part.


if ac.ProjectName != "" && !rc.AllowAutoCreate {
return errors.New("auto creation of projects is not supported in this integration")
if ac.ProjectName != "" {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and this validation at attachment time

Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev>
Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev>
Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev>
Copy link
Member

@danlishka danlishka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@migmartri migmartri merged commit 1f82638 into chainloop-dev:main Jul 30, 2023
@migmartri migmartri deleted the interpolation branch July 30, 2023 20:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants