Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cleanup old code
Browse files Browse the repository at this point in the history
riteshnoronha committed Oct 2, 2024

Verified

This commit was signed with the committer’s verified signature.
riteshnoronha Ritesh Noronha
1 parent 1fa8f14 commit 0f5f7c0
Showing 7 changed files with 249 additions and 342 deletions.
1 change: 0 additions & 1 deletion cmd/dt.go
Original file line number Diff line number Diff line change
@@ -62,7 +62,6 @@ Basic Example:
dtParams.PopulateInputField(ctx)

assembleParams, err := extractArgsFromDTtoAssemble(dtParams)
fmt.Println("assemble.Input: ", assembleParams.Input)
if err != nil {
return err
}
5 changes: 0 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -11,7 +11,6 @@ require (
github.com/google/go-github/v52 v52.0.0
github.com/google/uuid v1.6.0
github.com/mitchellh/copystructure v1.2.0
github.com/mitchellh/hashstructure/v2 v2.0.2
github.com/pingcap/log v1.1.0
github.com/samber/lo v1.47.0
github.com/spdx/tools-golang v0.5.5
@@ -27,21 +26,17 @@ require (
github.com/anchore/go-struct-converter v0.0.0-20230627203149-c72ef8859ca9 // indirect
github.com/cloudflare/circl v1.3.9 // indirect
github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/spdx/gordf v0.0.0-20221230105357-b735bd5aac89 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.9.0
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/oauth2 v0.22.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/text v0.17.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -48,8 +48,6 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw=
github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s=
github.com/mitchellh/hashstructure/v2 v2.0.2 h1:vGKWl0YJqUNxE8d+h8f6NJLcCJrgbhC4NcD46KavDd4=
github.com/mitchellh/hashstructure/v2 v2.0.2/go.mod h1:MG3aRVU/N29oo/V/IhBX8GR/zz4kQkprJgF2EVszyDE=
github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
github.com/pingcap/errors v0.11.0 h1:DCJQB8jrHbQ1VVlMFIrbj2ApScNNotVmkSNplu2yUt4=
8 changes: 1 addition & 7 deletions pkg/assemble/cdx/comp_service.go
Original file line number Diff line number Diff line change
@@ -23,12 +23,6 @@ import (
"github.com/interlynk-io/sbomasm/pkg/logger"
)

type item struct {
comp *cydx.Component
oldID string
newID string
}

type idmap struct {
oldID string
newID string
@@ -57,7 +51,7 @@ func (s *ComponentService) StoreAndCloneWithNewID(c *cydx.Component) *cydx.Compo
panic(err)
}

newID := newBomRef(nc)
newID := newBomRef()
nc.BOMRef = newID

s.idList = append(s.idList, idmap{
16 changes: 2 additions & 14 deletions pkg/assemble/cdx/interface.go
Original file line number Diff line number Diff line change
@@ -131,11 +131,6 @@ type MergeSettings struct {
}

func Merge(ms *MergeSettings) error {
merger := newMerge(ms)

merger.loadBoms()
merger.initOutBom()

if len(ms.Output.Spec) > 0 && ms.Output.Spec != "cyclonedx" {
return errors.New("invalid output spec")
}
@@ -144,13 +139,6 @@ func Merge(ms *MergeSettings) error {
return errors.New("invalid CycloneDX spec version")
}

if ms.Assemble.FlatMerge {
return merger.flatMerge()
} else if ms.Assemble.HierarchicalMerge {
return merger.hierarchicalMerge()
} else if ms.Assemble.AssemblyMerge {
return merger.assemblyMerge()
}

return merger.hierarchicalMerge()
merger := newMerge(ms)
return merger.combinedMerge()
}
447 changes: 162 additions & 285 deletions pkg/assemble/cdx/merge.go

Large diffs are not rendered by default.

112 changes: 84 additions & 28 deletions pkg/assemble/cdx/util.go
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ import (
"github.com/interlynk-io/sbomasm/pkg/detect"
"github.com/interlynk-io/sbomasm/pkg/logger"
"github.com/mitchellh/copystructure"
"github.com/mitchellh/hashstructure/v2"
"github.com/samber/lo"
"sigs.k8s.io/release-utils/version"
)

@@ -48,13 +48,10 @@ func newSerialNumber() string {
return fmt.Sprintf("urn:uuid:%s", u)
}

func newBomRef(obj interface{}) string {
f, _ := hashstructure.Hash(obj, hashstructure.FormatV2, &hashstructure.HashOptions{
ZeroNil: true,
SlicesAsSets: true,
})
func newBomRef() string {
u := uuid.New().String()

return fmt.Sprintf("%x", f)
return fmt.Sprintf("lynk:%s", u)
}

func cloneComp(c *cydx.Component) (*cydx.Component, error) {
@@ -66,6 +63,15 @@ func cloneComp(c *cydx.Component) (*cydx.Component, error) {
return compCopy.(*cydx.Component), nil
}

func cloneService(s *cydx.Service) (*cydx.Service, error) {
serviceCopy, err := copystructure.Copy(s)
if err != nil {
return nil, err
}

return serviceCopy.(*cydx.Service), nil
}

func loadBom(ctx context.Context, path string) (*cydx.BOM, error) {
log := logger.FromContext(ctx)

@@ -111,27 +117,6 @@ func utcNowTime() string {
return locationTime.Format(time.RFC3339)
}

func getAllTools(boms []*cydx.BOM) []cydx.Component {
tools := []cydx.Component{}

tools = append(tools, *toolInfo("sbomasm", version.GetVersionInfo().GitVersion, "Assembler for your sboms", "Interlynk", "https://interlynk.io", "support@interlynk.io", "Apache-2.0"))

for _, bom := range boms {
if bom.Metadata != nil && bom.Metadata.Tools != nil {
for _, tool := range *bom.Metadata.Tools.Tools {
tools = append(tools, *toolInfo(tool.Name, tool.Version, "", tool.Vendor, "", "", ""))
}
}

if bom.Metadata != nil && bom.Metadata.Tools != nil && bom.Metadata.Tools.Components != nil {
for _, tool := range *bom.Metadata.Tools.Components {
tools = append(tools, *toolInfo(tool.Name, tool.Version, "", "", "", "", ""))
}
}
}
return tools
}

func toolInfo(name, version, desc, sName, sUrl, sEmail, sLicense string) *cydx.Component {
return &cydx.Component{
Type: cydx.ComponentTypeApplication,
@@ -152,3 +137,74 @@ func toolInfo(name, version, desc, sName, sUrl, sEmail, sLicense string) *cydx.C
},
}
}

func buildToolList(in []*cydx.BOM) *cydx.ToolsChoice {
tools := cydx.ToolsChoice{}

tools.Services = &[]cydx.Service{}
tools.Components = &[]cydx.Component{}

*tools.Components = append(*tools.Components, *toolInfo("sbomasm", version.GetVersionInfo().GitVersion, "Assembler & Editor for your sboms", "Interlynk", "https://interlynk.io", "support@interlynk.io", "Apache-2.0"))

for _, bom := range in {
if bom.Metadata != nil && bom.Metadata.Tools != nil {
for _, tool := range *bom.Metadata.Tools.Tools {
*tools.Components = append(*tools.Components, *toolInfo(tool.Name, tool.Version, "", tool.Vendor, "", "", ""))
}
}

if bom.Metadata != nil && bom.Metadata.Tools != nil && bom.Metadata.Tools.Components != nil {
for _, tool := range *bom.Metadata.Tools.Components {
comp, _ := cloneComp(&tool)
*tools.Components = append(*tools.Components, *comp)
}
}

if bom.Metadata != nil && bom.Metadata.Tools != nil && bom.Metadata.Tools.Services != nil {
for _, service := range *bom.Metadata.Tools.Services {
serv, _ := cloneService(&service)
*tools.Services = append(*tools.Services, *serv)
}
}
}

return &tools
}

func buildComponentList(in []*cydx.BOM, cs *ComponentService) []cydx.Component {
return lo.Flatten(lo.Map(in, func(bom *cydx.BOM, _ int) []cydx.Component {
newComps := []cydx.Component{}
for _, comp := range lo.FromPtr(bom.Components) {
newComps = append(newComps, *cs.StoreAndCloneWithNewID(&comp))
}
return newComps
}))
}

func buildPrimaryComponentList(in []*cydx.BOM, cs *ComponentService) []cydx.Component {
return lo.Map(in, func(bom *cydx.BOM, _ int) cydx.Component {
if bom.Metadata != nil && bom.Metadata.Component != nil {
return *cs.StoreAndCloneWithNewID(bom.Metadata.Component)
}
return cydx.Component{}
})
}

func buildDependencyList(in []*cydx.BOM, cs *ComponentService) []cydx.Dependency {
return lo.Flatten(lo.Map(in, func(bom *cydx.BOM, _ int) []cydx.Dependency {
newDeps := []cydx.Dependency{}
for _, dep := range lo.FromPtr(bom.Dependencies) {
nd := cydx.Dependency{}
ref, found := cs.ResolveDepID(dep.Ref)
if !found {
continue
}

deps := cs.ResolveDepIDs(lo.FromPtr(dep.Dependencies))
nd.Ref = ref
nd.Dependencies = &deps
newDeps = append(newDeps, nd)
}
return newDeps
}))
}

0 comments on commit 0f5f7c0

Please sign in to comment.