sources

package
v0.5.6 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2025 License: GPL-3.0 Imports: 7 Imported by: 0

README

Sources Package

This package provides implementations of the core.Source interface for different artifact sources.

Components

GitHub Source

The GitHubSource implements the core.Source interface for downloading artifacts from GitHub releases.

Features
  • Downloads artifacts from GitHub release URLs
  • Supports GitHub token authentication via GITHUB_TOKEN environment variable
  • Validates GitHub URLs
  • Handles temporary file management for downloads
  • Provides proper cleanup of resources
Usage
source := sources.NewGitHubSource(logger)
artifact := &core.Artifact{
    Name:     "example",
    Version:  "1.0.0",
    Location: "https://github.com/owner/repo/releases/download/v1.0.0/artifact.zip",
}
content, err := source.Get(ctx, artifact)
Configuration

The GitHub source can be configured with:

  • Custom HTTP client
  • Custom logger
  • GitHub token (via environment variable)

Adding New Sources

To add a new source implementation:

  1. Create a new type that implements the core.Source interface
  2. Implement the required methods:
    • Get(ctx context.Context, artifact *core.Artifact) (io.ReadCloser, error)
    • List(ctx context.Context) ([]*core.Artifact, error)
    • Validate() error
  3. Add appropriate tests in the corresponding test file
  4. Update this README with documentation for the new source

Documentation

Overview

Package sources provides implementations of the core.Source interface.

Package sources provides implementations of the core.Source interface.

Package sources provides implementations of the core.Source interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateHTTPRequest added in v0.5.0

func CreateHTTPRequest(ctx context.Context, location string) (*http.Request, error)

CreateHTTPRequest creates a basic HTTP GET request with common headers.

Types

type GenericSource added in v0.5.0

type GenericSource struct {
	*HTTPSource
}

GenericSource implements core.Source for generic HTTP URLs. It doesn't perform any special validation or processing - it just downloads from any HTTP/HTTPS URL.

func NewGenericSource added in v0.5.0

func NewGenericSource(logger *logrus.Logger) *GenericSource

NewGenericSource creates a new GenericSource instance.

func (*GenericSource) Get added in v0.5.0

func (s *GenericSource) Get(ctx context.Context, artifact *core.Artifact) (io.ReadCloser, error)

Get retrieves an artifact from any HTTP/HTTPS URL.

func (*GenericSource) List added in v0.5.0

func (s *GenericSource) List(ctx context.Context) ([]*core.Artifact, error)

List is not implemented for generic source as it requires specific URLs.

func (*GenericSource) Validate added in v0.5.0

func (s *GenericSource) Validate() error

Validate checks if the source is properly configured.

type GitHubSource

type GitHubSource struct {
	*HTTPSource
}

GitHubSource implements core.Source for GitHub releases.

func NewGitHubSource

func NewGitHubSource(logger *logrus.Logger) *GitHubSource

NewGitHubSource creates a new GitHubSource instance.

func (*GitHubSource) Get

func (s *GitHubSource) Get(ctx context.Context, artifact *core.Artifact) (io.ReadCloser, error)

Get retrieves an artifact from GitHub.

func (*GitHubSource) List

func (s *GitHubSource) List(ctx context.Context) ([]*core.Artifact, error)

List is not implemented for GitHub source as it requires specific release URLs.

func (*GitHubSource) Validate

func (s *GitHubSource) Validate() error

Validate checks if the source is properly configured.

type HTTPSource added in v0.5.0

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

HTTPSource provides common functionality for HTTP-based sources.

func NewHTTPSource added in v0.5.0

func NewHTTPSource(logger *logrus.Logger, prefix string) *HTTPSource

NewHTTPSource creates a new HTTPSource instance.

func (*HTTPSource) Close added in v0.5.0

func (s *HTTPSource) Close() error

Close cleans up any temporary resources.

func (*HTTPSource) DoRequest added in v0.5.0

func (s *HTTPSource) DoRequest(req *http.Request) (*http.Response, error)

DoRequest performs an HTTP request and returns the response.

func (*HTTPSource) DownloadToTempFile added in v0.5.0

func (s *HTTPSource) DownloadToTempFile(resp *http.Response) (io.ReadCloser, error)

DownloadToTempFile downloads the content from the response to a temporary file.

func (*HTTPSource) EnsureTempDir added in v0.5.0

func (s *HTTPSource) EnsureTempDir() error

EnsureTempDir ensures that a temporary directory exists for downloads.

func (*HTTPSource) GetLogger added in v0.5.0

func (s *HTTPSource) GetLogger() *logrus.Logger

GetLogger returns the logger instance.

func (*HTTPSource) SetClient added in v0.5.0

func (s *HTTPSource) SetClient(client *http.Client)

SetClient sets a custom HTTP client (useful for testing).

Jump to

Keyboard shortcuts

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