remotefetcher

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2025 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrIgnoreFileNotFound = errors.New("remotefetcher: file not found")

ErrIgnoreFileNotFound is returned when the file is not found and should be ignored

Functions

func HashURL added in v0.9.0

func HashURL(url string) string

Types

type Cache

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

func NewCache

func NewCache(file, dir string) (*Cache, error)

func (*Cache) AddDataToStore

func (c *Cache) AddDataToStore(hash string, cacheData CacheData) error

func (*Cache) Get

func (c *Cache) Get(hash string) ([]byte, CacheData, bool)

func (*Cache) Set

func (c *Cache) Set(source, hash string, data []byte, dataType string) (CacheData, error)

Set stores data on disk and in the cache file and returns the cache data The filepath of the data is the file name + a SHA256 hash of the URL

type CacheData

type CacheData struct {
	Hash string `yaml:"hash"`
	Path string `yaml:"path"`
	Type string `yaml:"type"`
	URL  string `yaml:"url"`
}

func LoadMetadataFromFile

func LoadMetadataFromFile(filePath string) ([]*CacheData, error)

Function to read and parse the metadata file

type CachedFetcher

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

func (*CachedFetcher) Fetch

func (cf *CachedFetcher) Fetch(source string) ([]byte, error)

func (*CachedFetcher) Hash

func (cf *CachedFetcher) Hash(data []byte) string

func (*CachedFetcher) Parse

func (cf *CachedFetcher) Parse(data []byte, target interface{}) error

type FetcherConfig

type FetcherConfig struct {
	S3Client           *s3.Client
	HTTPClient         *http.Client
	FileType           string
	IgnoreFileNotFound bool
}

FetcherConfig holds the configuration for a fetcher.

type FetcherOption

type FetcherOption func(*FetcherConfig)

Option is a function that configures a fetcher.

func IgnoreFileNotFound

func IgnoreFileNotFound() FetcherOption

func WithFileType

func WithFileType(fileType string) FetcherOption

WithFileType ensures the default FileType will be yaml

func WithHTTPClient

func WithHTTPClient(client *http.Client) FetcherOption

WithHTTPClient sets the HTTP client for the fetcher.

func WithS3Client

func WithS3Client(client *s3.Client) FetcherOption

WithS3Client sets the S3 client for the fetcher.

type HTTPFetcher

type HTTPFetcher struct {
	HTTPClient *http.Client
	// contains filtered or unexported fields
}

func NewHTTPFetcher

func NewHTTPFetcher(options ...FetcherOption) *HTTPFetcher

NewHTTPFetcher creates a new instance of HTTPFetcher with the provided options.

func (*HTTPFetcher) Fetch

func (h *HTTPFetcher) Fetch(source string) ([]byte, error)

Fetch retrieves the file from the specified source URL

func (*HTTPFetcher) Hash

func (h *HTTPFetcher) Hash(data []byte) string

func (*HTTPFetcher) Parse

func (h *HTTPFetcher) Parse(data []byte, target interface{}) error

Parse decodes the raw data into the provided target structure

type LocalFetcher

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

func (*LocalFetcher) Fetch

func (l *LocalFetcher) Fetch(source string) ([]byte, error)

Fetch retrieves the file from the specified local file path

func (*LocalFetcher) Hash

func (l *LocalFetcher) Hash(data []byte) string

func (*LocalFetcher) Parse

func (l *LocalFetcher) Parse(data []byte, target interface{}) error

Parse decodes the raw data into the provided target structure

type RemoteFetcher

type RemoteFetcher interface {
	// Fetch retrieves the configuration from the specified URL or source
	// Returns the raw data as bytes or an error
	Fetch(source string) ([]byte, error)

	// Parse decodes the raw data into a Go structure (e.g., Commands, CommandLists)
	// Takes the raw data as input and populates the target interface
	Parse(data []byte, target interface{}) error

	// Hash returns the hash of the configuration data
	Hash(data []byte) string
}

func NewRemoteFetcher

func NewRemoteFetcher(source string, cache *Cache, options ...FetcherOption) (RemoteFetcher, error)

type S3Fetcher

type S3Fetcher struct {
	S3Client *minio.Client
	// contains filtered or unexported fields
}

func NewS3Fetcher

func NewS3Fetcher(endpoint string, options ...FetcherOption) (*S3Fetcher, error)

NewS3Fetcher creates a new instance of S3Fetcher with the provided options.

func (*S3Fetcher) Fetch

func (s *S3Fetcher) Fetch(source string) ([]byte, error)

Fetch retrieves the configuration from an S3 bucket Source should be in the format "bucket-name/object-key"

func (*S3Fetcher) Hash

func (s *S3Fetcher) Hash(data []byte) string

func (*S3Fetcher) Parse

func (s *S3Fetcher) Parse(data []byte, target interface{}) error

Parse decodes the raw data into the provided target structure

Jump to

Keyboard shortcuts

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