Skip to content

Commit

Permalink
Merge pull request #22 from interlynk-io/fix/github_tool_method
Browse files Browse the repository at this point in the history
fix github adapter tool method
  • Loading branch information
riteshnoronha authored Feb 5, 2025
2 parents 16c8fee + 5ad8073 commit bd82430
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
11 changes: 11 additions & 0 deletions pkg/source/github/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"net/http"

"github.com/interlynk-io/sbommv/pkg/iterator"
"github.com/interlynk-io/sbommv/pkg/logger"
"github.com/interlynk-io/sbommv/pkg/types"
"github.com/interlynk-io/sbommv/pkg/utils"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -78,6 +79,16 @@ func (g *GitHubAdapter) ParseAndValidateParams(cmd *cobra.Command) error {
return fmt.Errorf("missing or invalid flag: in-github-method")
}

if method == "tool" {
binaryPath, err := utils.GetBinaryPath()
if err != nil {
return fmt.Errorf("failed to get Syft binary: %w", err)
}
fmt.Println("Binary Path: ", binaryPath)
g.BinaryPath = binaryPath
logger.LogDebug(context.Background(), "Binary Path", "value", g.BinaryPath)
}

token := viper.GetString("GITHUB_TOKEN")

repoURL, version, err := utils.ParseRepoVersion(url)
Expand Down
26 changes: 17 additions & 9 deletions pkg/source/github/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ import (

// GitHubIterator iterates over SBOMs fetched from GitHub (API, Release, Tool)
type GitHubIterator struct {
ctx context.Context
client *Client
sboms []*iterator.SBOM // Stores all fetched SBOMs
position int // Tracks iteration position
ctx context.Context
client *Client
sboms []*iterator.SBOM // Stores all fetched SBOMs
position int // Tracks iteration position
binaryPath string
}

// NewGitHubIterator initializes the iterator based on the GitHub method
Expand All @@ -40,9 +41,10 @@ func NewGitHubIterator(ctx context.Context, g *GitHubAdapter) (*GitHubIterator,

client := NewClient(g.URL, g.Version, string(g.Method))
iterator := &GitHubIterator{
ctx: ctx,
client: client,
sboms: []*iterator.SBOM{},
ctx: ctx,
client: client,
sboms: []*iterator.SBOM{},
binaryPath: g.BinaryPath,
}

// Fetch SBOMs based on method
Expand Down Expand Up @@ -151,13 +153,19 @@ func (it *GitHubIterator) fetchSBOMFromTool() error {
}

// Generate SBOM
sbomFile, err := GenerateSBOM(it.ctx, repoDir, "/path/to/syft")
sbomFile, err := GenerateSBOM(it.ctx, repoDir, it.binaryPath)
if err != nil {
return fmt.Errorf("failed to generate SBOM: %w", err)
}

// Ensure the "sboms" directory exists
sbomDir := "sboms"
if err := os.MkdirAll(sbomDir, 0o755); err != nil {
return fmt.Errorf("failed to create SBOM output directory: %w", err)
}

// Move SBOM to final location
sbomFilePath := fmt.Sprintf("sboms/github_tool_sbom_%s.json", sanitizeRepoName(it.client.RepoURL))
sbomFilePath := fmt.Sprintf("%s/github_tool_sbom_%s.json", sbomDir, sanitizeRepoName(it.client.RepoURL))
if err := os.Rename(sbomFile, sbomFilePath); err != nil {
return fmt.Errorf("failed to move SBOM file: %w", err)
}
Expand Down

0 comments on commit bd82430

Please sign in to comment.