Documentation
¶
Overview ¶
Package fetchers provides template fetching from various sources (Git, S3, HTTP).
Index ¶
- type FetchOptions
- type FetchResult
- type Fetcher
- type FileReader
- type GitConfig
- type GitFetcher
- func (f *GitFetcher) CheckForUpdates(ctx context.Context, lastHash string) (string, bool, error)
- func (f *GitFetcher) Close() error
- func (f *GitFetcher) Fetch(ctx context.Context, opts FetchOptions) (*FetchResult, error)
- func (f *GitFetcher) ListFiles(ctx context.Context, extensions []string) ([]string, error)
- func (f *GitFetcher) ReadFile(ctx context.Context, path string) (io.ReadCloser, error)
- type HTTPConfig
- type HTTPFetcher
- func (f *HTTPFetcher) CheckForUpdates(ctx context.Context, lastHash string) (string, bool, error)
- func (f *HTTPFetcher) Close() error
- func (f *HTTPFetcher) Fetch(ctx context.Context, opts FetchOptions) (*FetchResult, error)
- func (f *HTTPFetcher) ListFiles(ctx context.Context, extensions []string) ([]string, error)
- func (f *HTTPFetcher) ReadFile(ctx context.Context, path string) (io.ReadCloser, error)
- type S3Config
- type S3Fetcher
- func (f *S3Fetcher) CheckForUpdates(ctx context.Context, lastHash string) (string, bool, error)
- func (f *S3Fetcher) Close() error
- func (f *S3Fetcher) Fetch(ctx context.Context, opts FetchOptions) (*FetchResult, error)
- func (f *S3Fetcher) ListFiles(ctx context.Context, extensions []string) ([]string, error)
- func (f *S3Fetcher) ReadFile(ctx context.Context, path string) (io.ReadCloser, error)
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 ¶
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 ¶
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 ¶
CheckForUpdates uses HEAD request with If-None-Match.
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) 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 ¶
NewS3Fetcher creates a new S3 fetcher.
func (*S3Fetcher) CheckForUpdates ¶
CheckForUpdates checks if S3 objects have changed.
func (*S3Fetcher) Fetch ¶
func (f *S3Fetcher) Fetch(ctx context.Context, opts FetchOptions) (*FetchResult, error)
Fetch downloads files from S3.