fetchers

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2026 License: GPL-3.0 Imports: 30 Imported by: 0

Documentation

Overview

Package fetchers provides template fetching from various sources (Git, S3, HTTP).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FetchOptions

type FetchOptions struct {
	// LastHash is the previous hash to check for changes
	// If current hash matches, fetch can be skipped
	LastHash string

	// Extensions filters files by extension (e.g., []string{".yaml", ".yml"})
	Extensions []string

	// MaxFileSize limits individual file size (0 = no limit)
	MaxFileSize int64

	// MaxTotalSize limits total download size (0 = no limit)
	MaxTotalSize int64
}

FetchOptions contains options for fetching.

type FetchResult

type FetchResult struct {
	// Files contains the fetched files (path -> content)
	Files map[string][]byte

	// Hash is a unique identifier for this version (commit hash, ETag, etc.)
	Hash string

	// FetchedAt is when the fetch completed
	FetchedAt time.Time

	// TotalFiles is the number of files found
	TotalFiles int

	// TotalSize is the total size of all files in bytes
	TotalSize int64
}

FetchResult contains the result of a fetch operation.

type Fetcher

type Fetcher interface {
	// Fetch downloads files from the source
	Fetch(ctx context.Context, opts FetchOptions) (*FetchResult, error)

	// CheckForUpdates returns the current hash without downloading
	// Returns nil if unable to determine (fetch required)
	CheckForUpdates(ctx context.Context, lastHash string) (string, bool, error)

	// Close releases any resources
	Close() error
}

Fetcher is the interface for template source fetchers.

type FileReader

type FileReader interface {
	// ReadFile reads a single file by path
	ReadFile(ctx context.Context, path string) (io.ReadCloser, error)

	// ListFiles returns all file paths matching the criteria
	ListFiles(ctx context.Context, extensions []string) ([]string, error)
}

FileReader provides streaming access to individual files.

type GitConfig

type GitConfig struct {
	URL        string
	Branch     string
	Path       string // Subdirectory to fetch from
	AuthType   string // none, token, ssh
	Token      string
	SSHKey     []byte
	SSHKeyPass string
}

GitConfig contains configuration for Git fetcher.

type GitFetcher

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

GitFetcher fetches templates from a Git repository. This fetcher is thread-safe and can be used concurrently.

func NewGitFetcher

func NewGitFetcher(config GitConfig) (*GitFetcher, error)

NewGitFetcher creates a new Git fetcher.

func (*GitFetcher) CheckForUpdates

func (f *GitFetcher) CheckForUpdates(ctx context.Context, lastHash string) (string, bool, error)

CheckForUpdates checks if the remote has new commits. This method is thread-safe.

func (*GitFetcher) Close

func (f *GitFetcher) Close() error

Close cleans up resources. This method is thread-safe.

func (*GitFetcher) Fetch

func (f *GitFetcher) Fetch(ctx context.Context, opts FetchOptions) (*FetchResult, error)

Fetch clones/pulls the repository and returns matching files. This method is thread-safe.

func (*GitFetcher) ListFiles

func (f *GitFetcher) ListFiles(ctx context.Context, extensions []string) ([]string, error)

ListFiles returns all files matching the extensions. This method is thread-safe.

func (*GitFetcher) ReadFile

func (f *GitFetcher) ReadFile(ctx context.Context, path string) (io.ReadCloser, error)

ReadFile reads a single file from the repository. This method is thread-safe and protected against path traversal attacks.

type HTTPConfig

type HTTPConfig struct {
	URL      string
	AuthType string            // none, bearer, basic, api_key
	Token    string            // Bearer token or API key
	Username string            // For basic auth
	Password string            // For basic auth
	Headers  map[string]string // Additional headers
	Timeout  time.Duration
}

HTTPConfig contains configuration for HTTP fetcher.

type HTTPFetcher

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

HTTPFetcher fetches templates from HTTP URLs. This fetcher is thread-safe and can be used concurrently.

func NewHTTPFetcher

func NewHTTPFetcher(config HTTPConfig) (*HTTPFetcher, error)

NewHTTPFetcher creates a new HTTP fetcher. Returns an error if the URL is blocked (SSRF prevention). The fetcher pins DNS resolution at creation time to prevent DNS rebinding attacks.

func (*HTTPFetcher) CheckForUpdates

func (f *HTTPFetcher) CheckForUpdates(ctx context.Context, lastHash string) (string, bool, error)

CheckForUpdates uses HEAD request with If-None-Match.

func (*HTTPFetcher) Close

func (f *HTTPFetcher) Close() error

Close releases resources.

func (*HTTPFetcher) Fetch

func (f *HTTPFetcher) Fetch(ctx context.Context, opts FetchOptions) (*FetchResult, error)

Fetch downloads files from the HTTP URL. Supports single files, .zip, .tar.gz, and .tgz archives.

func (*HTTPFetcher) ListFiles

func (f *HTTPFetcher) ListFiles(ctx context.Context, extensions []string) ([]string, error)

ListFiles returns file names (limited for HTTP).

func (*HTTPFetcher) ReadFile

func (f *HTTPFetcher) ReadFile(ctx context.Context, path string) (io.ReadCloser, error)

ReadFile reads a single file (only works for single-file URLs).

type S3Config

type S3Config struct {
	Bucket     string
	Region     string
	Prefix     string // Object prefix (folder path)
	Endpoint   string // Custom endpoint for S3-compatible services
	AuthType   string // keys, sts_role
	AccessKey  string
	SecretKey  string
	RoleARN    string
	ExternalID string
}

S3Config contains configuration for S3 fetcher.

type S3Fetcher

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

S3Fetcher fetches templates from S3/MinIO.

func NewS3Fetcher

func NewS3Fetcher(ctx context.Context, cfg S3Config) (*S3Fetcher, error)

NewS3Fetcher creates a new S3 fetcher.

func (*S3Fetcher) CheckForUpdates

func (f *S3Fetcher) CheckForUpdates(ctx context.Context, lastHash string) (string, bool, error)

CheckForUpdates checks if S3 objects have changed.

func (*S3Fetcher) Close

func (f *S3Fetcher) Close() error

Close releases resources.

func (*S3Fetcher) Fetch

func (f *S3Fetcher) Fetch(ctx context.Context, opts FetchOptions) (*FetchResult, error)

Fetch downloads files from S3.

func (*S3Fetcher) ListFiles

func (f *S3Fetcher) ListFiles(ctx context.Context, extensions []string) ([]string, error)

ListFiles returns all files matching the extensions.

func (*S3Fetcher) ReadFile

func (f *S3Fetcher) ReadFile(ctx context.Context, path string) (io.ReadCloser, error)

ReadFile reads a single file from S3.

Jump to

Keyboard shortcuts

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