remote

package
v0.23.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 7 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Remote Repository Analysis

This package provides language-agnostic remote repository analysis capabilities for omnibump.

Features

  • Fetch dependency manifest files from remote repositories (GitHub, GitLab, etc.)
  • No cloning required - uses repository APIs
  • Recursive search for manifest files (finds nested go.mod, pom.xml, etc.)
  • Supports multi-module repositories

Usage

import (
    "context"
    "github.com/chainguard-dev/omnibump/pkg/remote"
    omnibump_go "github.com/chainguard-dev/omnibump/pkg/languages/golang"
)

// Create GitHub fetcher
fetcher := remote.NewGitHubFetcher(yourGitHubClient)

// Search for go.mod files
repo := remote.RepositoryRef{
    Owner: "spiffe",
    Repo:  "spire",
    Ref:   "v1.10.3",
}

files, err := fetcher.SearchFiles(ctx, repo, []string{"go.mod"})

// Convert to map for analysis
fileMap := make(map[string][]byte)
for _, f := range files {
    fileMap[f.Path] = f.Content
}

// Analyze with omnibump
analyzer := &omnibump_go.GolangAnalyzer{}
result, err := analyzer.AnalyzeRemote(ctx, fileMap)

// Result contains analysis for each found file
for _, fa := range result.FileAnalyses {
    fmt.Printf("File: %s\n", fa.FilePath)
    fmt.Printf("Dependencies: %d\n", len(fa.Analysis.Dependencies))
}

Integration Tests

Integration tests verify the complete workflow using real GitHub repositories.

Running Integration Tests
# Set GitHub token
export GITHUB_TOKEN=your_token_here

# Run all integration tests
go test -tags=integration ./pkg/remote/... -v
go test -tags=integration ./pkg/languages/golang/... -run Remote -v

# Run specific test
go test -tags=integration ./pkg/remote/... -run TestGitHubFetcher_SearchFiles_SpireServer -v
Test Repositories

The integration tests use these real repositories:

  • spiffe/spire - Single module with sigstore dependencies
  • aws/amazon-ssm-agent - Contains golang.org/x/crypto
  • hashicorp/consul - Uses replace directives
  • kubernetes/kubernetes - Multi-module repository
  • elastic/beats - Contains pseudo-version dependencies
What Gets Tested
  1. GitHub Fetcher (pkg/remote/github_integration_test.go):

    • Searching for files by pattern
    • Fetching specific files
    • Handling multi-module repos
    • Error cases (non-existent files, etc.)
  2. Remote Analysis (pkg/languages/golang/remote_integration_test.go):

    • Complete workflow: fetch → analyze
    • Dependency discovery and version tracking
    • Replace directive handling
    • Multi-module analysis
    • CVE remediation scenarios

Implementing Other Languages

To add remote support for other languages (Maven, Rust, etc.):

  1. Implement AnalyzeRemote() in your language's analyzer
  2. Add integration tests using real repos
  3. Update manifest file patterns (e.g., ["pom.xml"], ["Cargo.toml"])

Example for Maven:

func (ma *MavenAnalyzer) AnalyzeRemote(ctx context.Context, files map[string][]byte) (*analyzer.RemoteAnalysisResult, error) {
    // Similar to Go implementation
    result := &analyzer.RemoteAnalysisResult{
        Language: "maven",
        FileAnalyses: []analyzer.FileAnalysis{},
    }

    for path, content := range files {
        // Parse pom.xml from content
        // Add to result.FileAnalyses
    }

    return result, nil
}

Documentation

Overview

Package remote provides interfaces for fetching dependency manifest files from remote repositories.

Index

Constants

View Source
const (
	// MaxFileSize is the maximum allowed file size in bytes (10 MB).
	MaxFileSize = 10 * 1024 * 1024

	// MaxPathLength is the maximum allowed path length.
	MaxPathLength = 4096

	// MaxRefLength is the maximum allowed git reference length.
	MaxRefLength = 256

	// MaxOwnerLength is the maximum allowed owner/org name length.
	MaxOwnerLength = 256

	// MaxRepoLength is the maximum allowed repository name length.
	MaxRepoLength = 256

	// MaxHostLength is the maximum allowed DNS hostname length.
	MaxHostLength = 253
)

Variables

View Source
var (
	// ErrRepositoryRefNil is returned when a repository reference is nil.
	ErrRepositoryRefNil = errors.New("repository reference cannot be nil")

	// ErrEmptyField is returned when a required field is empty.
	ErrEmptyField = errors.New("field cannot be empty")

	// ErrFieldTooLong is returned when a field exceeds maximum length.
	ErrFieldTooLong = errors.New("field exceeds maximum length")

	// ErrInvalidCharacters is returned when a field contains invalid characters.
	ErrInvalidCharacters = errors.New("contains invalid characters")

	// ErrCommandInjection is returned when a value could enable command injection.
	ErrCommandInjection = errors.New("potential command injection")

	// ErrPathTraversal is returned when a path contains traversal attempts.
	ErrPathTraversal = errors.New("path traversal attempt")

	// ErrAbsolutePath is returned when a path is absolute instead of relative.
	ErrAbsolutePath = errors.New("path must be relative, not absolute")

	// ErrNegativeSize is returned when content size is negative.
	ErrNegativeSize = errors.New("content size cannot be negative")

	// ErrFileTooLarge is returned when a file exceeds size limits.
	ErrFileTooLarge = errors.New("file size exceeds maximum")

	// ErrSearchOperatorInjection is returned when a pattern contains GitHub search operators.
	ErrSearchOperatorInjection = errors.New("pattern cannot contain GitHub search operator")

	// ErrPatternContainsPath is returned when a pattern contains path separators.
	ErrPatternContainsPath = errors.New("pattern cannot contain path separators")
)

Functions

func ValidateContentSize

func ValidateContentSize(size int, path string) error

ValidateContentSize validates that content size is within acceptable limits.

func ValidatePath

func ValidatePath(path string) error

ValidatePath validates a file path to prevent path traversal attacks.

Types

type GitHubFetcher

type GitHubFetcher struct {
	// contains filtered or unexported fields
}

GitHubFetcher implements RemoteFetcher using the GitHub API.

func NewGitHubFetcher

func NewGitHubFetcher(client GitHubSearcher) *GitHubFetcher

NewGitHubFetcher creates a new GitHub-based remote fetcher.

func (*GitHubFetcher) GetFile

func (g *GitHubFetcher) GetFile(ctx context.Context, repo RepositoryRef, path string) (*RemoteFile, error)

GetFile fetches a specific file from a repository. Implements RemoteFetcher.GetFile.

func (*GitHubFetcher) ListFilePaths added in v0.14.4

func (g *GitHubFetcher) ListFilePaths(ctx context.Context, repo RepositoryRef) ([]string, error)

ListFilePaths returns all file paths in a repository at the given ref using the Git Tree API (one request, not subject to Code Search rate limits). Useful for language detection before calling SearchFiles.

func (*GitHubFetcher) SearchFiles

func (g *GitHubFetcher) SearchFiles(ctx context.Context, repo RepositoryRef, patterns []string) ([]RemoteFile, error)

SearchFiles searches for files matching the given patterns in a repository. Implements RemoteFetcher.SearchFiles.

Files are discovered by listing the full tree at the requested ref via the Git Tree API rather than GitHub Code Search: Code Search only indexes the default branch (returning paths that may not exist at the ref) and caps results at 100 per query.

type GitHubSearcher

type GitHubSearcher interface {
	// GetFileContent fetches the content of a file at a specific ref.
	GetFileContent(ctx context.Context, owner, repo, path, ref string) ([]byte, error)

	// ListFilePaths returns all file paths in a repository at the given ref using
	// the Git Tree API (one request, not subject to Code Search rate limits).
	// Useful for language detection before calling SearchFiles.
	ListFilePaths(ctx context.Context, owner, repo, ref string) ([]string, error)
}

GitHubSearcher defines the minimal interface needed to search and fetch files from GitHub. This allows omnibump to work with different GitHub client implementations.

type RemoteFetcher

type RemoteFetcher interface {
	// SearchFiles searches for files matching the given patterns in a repository.
	// Recursively searches the entire repository tree.
	// patterns is a list of filename patterns to search for (e.g., ["go.mod", "pom.xml"])
	// Returns a list of ALL found files with their paths and content.
	// For multi-module repos, this will return multiple files (e.g., go.mod, api/go.mod, server/go.mod).
	SearchFiles(ctx context.Context, repo RepositoryRef, patterns []string) ([]RemoteFile, error)

	// GetFile fetches a specific file from a repository.
	GetFile(ctx context.Context, repo RepositoryRef, path string) (*RemoteFile, error)
}

RemoteFetcher defines the interface for fetching files from remote repositories. Implementations can support different providers (GitHub, GitLab, Gitea, etc.)

type RemoteFile

type RemoteFile struct {
	// Path is the file path relative to repository root
	// Examples: "go.mod", "api/go.mod", "pkg/server/go.mod"
	Path string

	// Content is the file content as bytes
	Content []byte

	// Metadata stores additional information about the file
	Metadata map[string]string
}

RemoteFile represents a file fetched from a remote repository.

type RepositoryRef

type RepositoryRef struct {
	// Host is the git host (e.g., "github.com", "gitlab.com")
	Host string

	// Owner is the repository owner/organization
	Owner string

	// Repo is the repository name
	Repo string

	// Ref is the git reference (tag, branch, or commit SHA)
	Ref string
}

RepositoryRef identifies a remote repository and ref (tag/branch/commit).

func (*RepositoryRef) Validate

func (r *RepositoryRef) Validate() error

Validate validates all fields of a RepositoryRef.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL