Skip to content

Commit

Permalink
replace repo by namespace
Browse files Browse the repository at this point in the history
Signed-off-by: Vivek Kumar Sahu <[email protected]>
  • Loading branch information
viveksahu26 committed Feb 19, 2025
1 parent 296a29b commit 16c1ec3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
10 changes: 5 additions & 5 deletions pkg/iterator/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import (

// SBOM represents a single SBOM file
type SBOM struct {
Path string // File path (empty if stored in memory)
Data []byte // SBOM data stored in memory (nil if using Path)
Repo string // Repository URL (helps track multi-repo processing)
Version string // Version of the SBOM (e.g., "latest" or "v1.2.3")
Branch string // github repo main, master, or any specific branch
Path string // File path (empty if stored in memory)
Data []byte // SBOM data stored in memory (nil if using Path)
Namespace string // It could be Repo, or Dir (helps track multi-repo or multi-folder processing)
Version string // Version of the SBOM (e.g., "latest" or "v1.2.3")
Branch string // github repo main, master, or any specific branch
}

// SBOMIterator provides a way to lazily fetch SBOMs one by one
Expand Down
6 changes: 3 additions & 3 deletions pkg/source/github/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ func (g *GitHubAdapter) DryRun(ctx *tcontext.TransferMetadata, iterator iterator
continue
}
// Update processor with current SBOM data
processor.Update(sbom.Data, sbom.Repo, sbom.Path)
processor.Update(sbom.Data, sbom.Namespace, sbom.Path)

doc, err := processor.ProcessSBOMs()
if err != nil {
Expand All @@ -425,7 +425,7 @@ func (g *GitHubAdapter) DryRun(ctx *tcontext.TransferMetadata, iterator iterator

// If outputDir is provided, save the SBOM file
if outputDir != "" {
if err := processor.WriteSBOM(doc, sbom.Repo); err != nil {
if err := processor.WriteSBOM(doc, sbom.Namespace); err != nil {
logger.LogError(ctx.Context, err, "Failed to write SBOM to output directory")
}
}
Expand All @@ -441,7 +441,7 @@ func (g *GitHubAdapter) DryRun(ctx *tcontext.TransferMetadata, iterator iterator
}

sbomCount++
fmt.Printf(" - 📁 Repo: %s | Format: %s | SpecVersion: %s | Filename: %s \n", sbom.Repo, doc.Format, doc.SpecVersion, doc.Filename)
fmt.Printf(" - 📁 Repo: %s | Format: %s | SpecVersion: %s | Filename: %s \n", sbom.Namespace, doc.Format, doc.SpecVersion, doc.Filename)

// logger.LogInfo(ctx.Context, fmt.Sprintf("%d. Repo: %s | Format: %s | SpecVersion: %s | Filename: %s",
// sbomCount, sbom.Repo, doc.Format, doc.SpecVersion, doc.Filename))
Expand Down
26 changes: 13 additions & 13 deletions pkg/source/github/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ func (it *GitHubIterator) fetchSBOMFromAPI(ctx *tcontext.TransferMetadata) error
}

it.sboms = append(it.sboms, &iterator.SBOM{
Path: "",
Data: sbomData,
Repo: fmt.Sprintf("%s/%s", it.client.Owner, it.client.Repo),
Version: "latest",
Path: "",
Data: sbomData,
Namespace: fmt.Sprintf("%s/%s", it.client.Owner, it.client.Repo),
Version: "latest",
})
return nil
}
Expand All @@ -119,10 +119,10 @@ func (it *GitHubIterator) fetchSBOMFromReleases(ctx *tcontext.TransferMetadata)
for version, sbomDataList := range sbomFiles {
for _, sbomData := range sbomDataList { // sbomPath is a string (file path)
it.sboms = append(it.sboms, &iterator.SBOM{
Path: sbomData.Filename,
Data: sbomData.Content,
Repo: fmt.Sprintf("%s/%s", it.client.Owner, it.client.Repo),
Version: version,
Path: sbomData.Filename,
Data: sbomData.Content,
Namespace: fmt.Sprintf("%s/%s", it.client.Owner, it.client.Repo),
Version: version,
})
}
}
Expand Down Expand Up @@ -157,11 +157,11 @@ func (it *GitHubIterator) fetchSBOMFromTool(ctx *tcontext.TransferMetadata) erro
}

it.sboms = append(it.sboms, &iterator.SBOM{
Path: "",
Data: sbomBytes,
Repo: fmt.Sprintf("%s/%s", it.client.Owner, it.client.Repo),
Version: it.client.Version,
Branch: it.client.Branch,
Path: "",
Data: sbomBytes,
Namespace: fmt.Sprintf("%s/%s", it.client.Owner, it.client.Repo),
Version: it.client.Version,
Branch: it.client.Branch,
})
logger.LogDebug(ctx.Context, "SBOM successfully stored in memory", "repository", it.client.RepoURL)
return nil
Expand Down
12 changes: 6 additions & 6 deletions pkg/target/interlynk/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,9 @@ func (i *InterlynkAdapter) uploadSequential(ctx *tcontext.TransferMetadata, sbom
}
errorCount = 0 // Reset error counter on successful iteration

logger.LogDebug(ctx.Context, "Uploading SBOM", "repo", sbom.Repo, "version", sbom.Version, "data size", len(sbom.Data))
logger.LogDebug(ctx.Context, "Uploading SBOM", "repo", sbom.Namespace, "version", sbom.Version, "data size", len(sbom.Data))

projectID, err := client.FindOrCreateProjectGroup(ctx, sbom.Repo)
projectID, err := client.FindOrCreateProjectGroup(ctx, sbom.Namespace)
if err != nil {
logger.LogInfo(ctx.Context, "error", err)
continue
Expand All @@ -219,9 +219,9 @@ func (i *InterlynkAdapter) uploadSequential(ctx *tcontext.TransferMetadata, sbom
// Upload SBOM content (stored in memory)
err = client.UploadSBOM(ctx, projectID, sbom.Data)
if err != nil {
logger.LogInfo(ctx.Context, "Failed to upload SBOM", "repo", sbom.Repo, "version", sbom.Version)
logger.LogInfo(ctx.Context, "Failed to upload SBOM", "repo", sbom.Namespace, "version", sbom.Version)
} else {
logger.LogDebug(ctx.Context, "Successfully uploaded SBOM", "repo", sbom.Repo, "version", sbom.Version)
logger.LogDebug(ctx.Context, "Successfully uploaded SBOM", "repo", sbom.Namespace, "version", sbom.Version)
}
}

Expand Down Expand Up @@ -265,7 +265,7 @@ func (i *InterlynkAdapter) DryRun(ctx *tcontext.TransferMetadata, sbomIterator i
}

// Update processor with current SBOM data
processor.Update(sbom.Data, sbom.Repo, sbom.Path)
processor.Update(sbom.Data, sbom.Namespace, sbom.Path)

// Process SBOM to extract metadata
doc, err := processor.ProcessSBOMs()
Expand All @@ -275,7 +275,7 @@ func (i *InterlynkAdapter) DryRun(ctx *tcontext.TransferMetadata, sbomIterator i
}

// Identify project name (repo-version)
projectKey := fmt.Sprintf("%s", sbom.Repo)
projectKey := fmt.Sprintf("%s", sbom.Namespace)
projectSBOMs[projectKey] = append(projectSBOMs[projectKey], doc)
totalSBOMs++
uniqueFormats[string(doc.Format)] = struct{}{}
Expand Down

0 comments on commit 16c1ec3

Please sign in to comment.