Skip to content

Conversation

@pkwiatkowski1
Copy link
Contributor

@pkwiatkowski1 pkwiatkowski1 commented Jul 29, 2024

6. Merge subcommand

Date: 2024-07-29

Status

Accepted

Context

SBOM merge capability should be supported.

Decision

  • Ability to take one or more SBOMs in different formats into a singular sbom

    • Merge components that may match on different identifiers (purls, hash, etc …)
      • Merge component dependencies
      • Merge component properties
  • Ability to take a flag to “flatten” any externally referenced SBOMs

    • Any nested components should be moved to "top level" components and the depends_on section updated to show the dependency.

Consequences

These changes allow end users to easily consolidate multiple SBOMs from a variety of different sources into one while still being agnostic of the SBOM format being used.

Signed-off-by: Patrick Kwiatkowski <patrick.r.kwiatkowski@lmco.com>
Signed-off-by: Patrick Kwiatkowski <patrick.r.kwiatkowski@lmco.com>
@jhoward-lm jhoward-lm added the documentation Improvements or additions to documentation label Jul 30, 2024
@jhoward-lm
Copy link
Contributor

jhoward-lm commented Aug 3, 2024

Just to document here for whoever ends up working on this, I think an implementation using a Go generic interface would be a clean way to do it.

Basic example
package main

import (
	"fmt"

	"github.com/protobom/protobom/pkg/sbom"
)

type (
	Merger[T any] interface {
		Merge(*T) error
	}

	MergerBase[T any] struct {
		Base *T
	}
)

func (*MergerBase[T]) Merge(t *T) error {
	switch any(t).(type) {
	case *sbom.Metadata:
		fmt.Println("Merging metadata")
	case *sbom.Node:
		if _, ok := any(m.Base).(*sbom.Node); !ok {
			// return error
		}

		fmt.Println("Merging nodes")
	case *sbom.NodeList:
		fmt.Println("Merging node lists")
	case *sbom.Person:
		fmt.Println("Merging persons")
	case *sbom.Tool:
		fmt.Println("Merging tools")
	default:
		// return error
	}

	return nil
}

func NewMerger[T any](data *T) *MergerBase[T] {
	return &MergerBase[T]{Base: data}
}

// Enforce implementation of interface at compile time
var _ Merger[sbom.Node] = (*MergerBase[sbom.Node])(nil)

func main() {
	merger := NewMerger(&sbom.Node{})
	merger.Merge(&sbom.Node{})
}

Go playground link

Signed-off-by: Patrick Kwiatkowski <patrick.r.kwiatkowski@lmco.com>
@pkwiatkowski1 pkwiatkowski1 marked this pull request as ready for review August 5, 2024 19:29
@pkwiatkowski1 pkwiatkowski1 requested a review from a team as a code owner August 5, 2024 19:29
@idunbarh idunbarh added the adr Architecture Decision Records use to decide architecture or implementation details of `bomctl` label Aug 26, 2024
Signed-off-by: Allen Shearin <allen.p.shearin@gmail.com>
@ashearin ashearin requested a review from jhoward-lm October 23, 2024 14:41
@jhoward-lm jhoward-lm merged commit 5015e8f into bomctl:main Nov 25, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

adr Architecture Decision Records use to decide architecture or implementation details of `bomctl` documentation Improvements or additions to documentation

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants