source

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package source provides interfaces and implementations for cookbook sources.

Index

Constants

View Source
const PUBLIC_SUPERMARKET = "https://supermarket.chef.io"

Variables

View Source
var (
	// ErrNotImplemented is returned when a source doesn't implement an optional method.
	ErrNotImplemented = errors.New("method not implemented")

	// ErrInvalidSource is returned when a source configuration is invalid.
	ErrInvalidSource = errors.New("invalid source configuration")

	// ErrAuthenticationRequired is returned when authentication is needed but not provided.
	ErrAuthenticationRequired = errors.New("authentication required")
)

Common errors

Functions

This section is empty.

Types

type ChefServerSource

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

ChefServerSource implements CookbookSource for Chef Server API.

func NewChefServerSource

func NewChefServerSource(baseURL, clientName, clientKey string) (*ChefServerSource, error)

NewChefServerSource creates a new Chef Server source.

func (*ChefServerSource) DownloadAndExtractCookbook

func (s *ChefServerSource) DownloadAndExtractCookbook(ctx context.Context, cookbook *berkshelf.Cookbook, targetDir string) error

DownloadAndExtractCookbook downloads the cookbook files and extracts them to the specified directory.

func (*ChefServerSource) FetchCookbook

func (s *ChefServerSource) FetchCookbook(ctx context.Context, name string, version *berkshelf.Version) (*berkshelf.Cookbook, error)

FetchCookbook downloads the complete cookbook at the specified version.

func (*ChefServerSource) FetchMetadata

func (s *ChefServerSource) FetchMetadata(ctx context.Context, name string, version *berkshelf.Version) (*berkshelf.Metadata, error)

FetchMetadata downloads just the metadata for a cookbook version.

func (*ChefServerSource) GetSourceLocation

func (s *ChefServerSource) GetSourceLocation() *berkshelf.SourceLocation

GetSourceLocation returns the source location for this chef server source

func (*ChefServerSource) GetSourceType

func (s *ChefServerSource) GetSourceType() string

GetSourceType returns the source type

func (*ChefServerSource) GetSourceURL

func (s *ChefServerSource) GetSourceURL() string

GetSourceURL returns the source URL

func (*ChefServerSource) ListVersions

func (s *ChefServerSource) ListVersions(ctx context.Context, name string) ([]*berkshelf.Version, error)

ListVersions returns all available versions of a cookbook.

func (*ChefServerSource) Name

func (s *ChefServerSource) Name() string

Name returns the name of this source.

func (*ChefServerSource) Priority

func (s *ChefServerSource) Priority() int

Priority returns the priority of this source.

func (*ChefServerSource) Search

func (s *ChefServerSource) Search(ctx context.Context, query string) ([]*berkshelf.Cookbook, error)

Search returns cookbooks matching the query.

func (*ChefServerSource) SetPriority

func (s *ChefServerSource) SetPriority(priority int)

SetPriority sets the priority of this source.

type CookbookSource

type CookbookSource interface {
	// Name returns the human-readable name of this source.
	Name() string

	// Priority returns the priority of this source (higher = preferred).
	Priority() int

	// ListVersions returns all available versions of a cookbook.
	ListVersions(ctx context.Context, name string) ([]*berkshelf.Version, error)

	// FetchCookbook downloads the complete cookbook at the specified version.
	FetchCookbook(ctx context.Context, name string, version *berkshelf.Version) (*berkshelf.Cookbook, error)

	// FetchMetadata downloads just the metadata for a cookbook version.
	FetchMetadata(ctx context.Context, name string, version *berkshelf.Version) (*berkshelf.Metadata, error)

	// DownloadAndExtractCookbook downloads the cookbook files and extracts them to the specified directory.
	DownloadAndExtractCookbook(ctx context.Context, cookbook *berkshelf.Cookbook, targetDir string) error

	// Search returns cookbooks matching the query (optional, may return ErrNotImplemented).
	Search(ctx context.Context, query string) ([]*berkshelf.Cookbook, error)

	// GetSourceLocation returns the source location for this source
	GetSourceLocation() *berkshelf.SourceLocation

	// GetSourceType returns the source type
	GetSourceType() string

	// GetSourceURL returns the source URL
	GetSourceURL() string
}

CookbookSource defines the interface for fetching cookbooks from various sources.

type ErrCookbookNotFound

type ErrCookbookNotFound struct {
	Name    string
	Version string
}

ErrCookbookNotFound is returned when a cookbook cannot be found.

func (*ErrCookbookNotFound) Error

func (e *ErrCookbookNotFound) Error() string

type ErrInvalidMetadata

type ErrInvalidMetadata struct {
	Name   string
	Reason string
}

ErrInvalidMetadata is returned when cookbook metadata is invalid or corrupt.

func (*ErrInvalidMetadata) Error

func (e *ErrInvalidMetadata) Error() string

type ErrSourceUnavailable

type ErrSourceUnavailable struct {
	Source string
	Reason string
}

ErrSourceUnavailable is returned when a source is temporarily unavailable.

func (*ErrSourceUnavailable) Error

func (e *ErrSourceUnavailable) Error() string

type ErrVersionNotFound

type ErrVersionNotFound struct {
	Name    string
	Version string
}

ErrVersionNotFound is returned when a specific version cannot be found.

func (*ErrVersionNotFound) Error

func (e *ErrVersionNotFound) Error() string

type Factory

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

Factory creates CookbookSource instances from Berksfile entries.

func NewFactory

func NewFactory() *Factory

NewFactory creates a new source factory.

func (*Factory) AddDefaultSource

func (f *Factory) AddDefaultSource(source CookbookSource)

AddDefaultSource adds a default source to use when no specific source is specified.

func (*Factory) CreateFromBerksfile

func (f *Factory) CreateFromBerksfile(bf *berksfile.Berksfile) (*Manager, error)

CreateFromBerksfile creates a Manager with sources from a Berksfile.

func (*Factory) CreateFromLocation

func (f *Factory) CreateFromLocation(location *berkshelf.SourceLocation) (CookbookSource, error)

CreateFromLocation creates a source from a SourceLocation.

func (*Factory) CreateFromURL

func (f *Factory) CreateFromURL(url string) (CookbookSource, error)

CreateFromURL creates a source from a URL string (public method)

func (*Factory) CreateSourceForCookbook

func (f *Factory) CreateSourceForCookbook(cookbook *berksfile.CookbookDef) ([]CookbookSource, error)

CreateSourceForCookbook creates appropriate sources for a cookbook definition.

type GitSource

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

GitSource implements CookbookSource for Git repositories.

func NewGitSource

func NewGitSource(uri string, opts *berkshelf.SourceLocation) (*GitSource, error)

NewGitSource creates a new Git source.

func (*GitSource) DownloadAndExtractCookbook

func (g *GitSource) DownloadAndExtractCookbook(ctx context.Context, cookbook *berkshelf.Cookbook, targetDir string) error

DownloadAndExtractCookbook copies the cookbook files from the Git cache to the target directory.

func (*GitSource) FetchCookbook

func (g *GitSource) FetchCookbook(ctx context.Context, name string, version *berkshelf.Version) (*berkshelf.Cookbook, error)

FetchCookbook downloads the complete cookbook.

func (*GitSource) FetchMetadata

func (g *GitSource) FetchMetadata(ctx context.Context, name string, version *berkshelf.Version) (*berkshelf.Metadata, error)

FetchMetadata reads the metadata from the cloned repository.

func (*GitSource) GetBranch

func (g *GitSource) GetBranch() string

GetBranch returns the branch for this Git source.

func (*GitSource) GetRef

func (g *GitSource) GetRef() string

GetRef returns the ref for this Git source.

func (*GitSource) GetRevision

func (g *GitSource) GetRevision() string

GetRevision returns the revision for this Git source.

func (*GitSource) GetSourceLocation

func (g *GitSource) GetSourceLocation() *berkshelf.SourceLocation

GetSourceLocation returns the source location for this git source

func (*GitSource) GetSourceType

func (g *GitSource) GetSourceType() string

GetSourceType returns the source type

func (*GitSource) GetSourceURL

func (g *GitSource) GetSourceURL() string

GetSourceURL returns the source URL

func (*GitSource) GetTag

func (g *GitSource) GetTag() string

GetTag returns the tag for this Git source.

func (*GitSource) ListVersions

func (g *GitSource) ListVersions(ctx context.Context, name string) ([]*berkshelf.Version, error)

ListVersions returns available versions (tags) from the Git repository.

func (*GitSource) Name

func (g *GitSource) Name() string

Name returns the name of this source.

func (*GitSource) Priority

func (g *GitSource) Priority() int

Priority returns the priority of this source.

func (*GitSource) Search

func (g *GitSource) Search(ctx context.Context, query string) ([]*berkshelf.Cookbook, error)

Search is not implemented for Git sources.

type Manager

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

Manager coordinates multiple sources.

func NewManager

func NewManager() *Manager

NewManager creates a new source manager.

func (*Manager) AddSource

func (m *Manager) AddSource(source CookbookSource)

AddSource adds a cookbook source to the manager.

func (*Manager) FetchCookbook

func (m *Manager) FetchCookbook(ctx context.Context, name string, version *berkshelf.Version) (*berkshelf.Cookbook, error)

FetchCookbook tries to fetch a cookbook from sources in priority order.

func (*Manager) GetSources

func (m *Manager) GetSources() []CookbookSource

GetSources returns all sources in the manager

func (*Manager) ListVersions

func (m *Manager) ListVersions(ctx context.Context, name string) ([]*berkshelf.Version, error)

ListVersions queries all sources for available versions.

type PathSource

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

PathSource implements CookbookSource for local filesystem paths.

func NewPathSource

func NewPathSource(path string) (*PathSource, error)

NewPathSource creates a new path-based cookbook source.

func (*PathSource) DownloadAndExtractCookbook

func (p *PathSource) DownloadAndExtractCookbook(ctx context.Context, cookbook *berkshelf.Cookbook, targetDir string) error

DownloadAndExtractCookbook copies the cookbook files from the local path to the target directory.

func (*PathSource) FetchCookbook

func (p *PathSource) FetchCookbook(ctx context.Context, name string, version *berkshelf.Version) (*berkshelf.Cookbook, error)

FetchCookbook returns the cookbook from the path.

func (*PathSource) FetchMetadata

func (p *PathSource) FetchMetadata(ctx context.Context, name string, version *berkshelf.Version) (*berkshelf.Metadata, error)

FetchMetadata returns the metadata for a cookbook.

func (*PathSource) GetSourceLocation

func (p *PathSource) GetSourceLocation() *berkshelf.SourceLocation

GetSourceLocation returns the source location for this path source

func (*PathSource) GetSourceType

func (p *PathSource) GetSourceType() string

GetSourceType returns the source type

func (*PathSource) GetSourceURL

func (p *PathSource) GetSourceURL() string

GetSourceURL returns the source URL (empty for path sources)

func (*PathSource) ListVersions

func (p *PathSource) ListVersions(ctx context.Context, name string) ([]*berkshelf.Version, error)

ListVersions returns the versions available in the path source.

func (*PathSource) Name

func (p *PathSource) Name() string

Name returns the name of this source.

func (*PathSource) Priority

func (p *PathSource) Priority() int

Priority returns the priority of this source.

func (*PathSource) ReadMetadata added in v0.0.4

func (p *PathSource) ReadMetadata(cookbookPath string) (*berkshelf.Metadata, error)

ReadMetadata reads cookbook metadata from a directory.

func (*PathSource) ReadMetadataJSON added in v0.0.4

func (p *PathSource) ReadMetadataJSON(path string) (*berkshelf.Metadata, error)

ReadMetadataJSON parses a metadata.json file.

func (*PathSource) ReadMetadataRB added in v0.0.4

func (p *PathSource) ReadMetadataRB(path string, cookbookPath string) (*berkshelf.Metadata, error)

ReadMetadataRB parses a metadata.rb file (simplified).

func (*PathSource) Search

func (p *PathSource) Search(ctx context.Context, query string) ([]*berkshelf.Cookbook, error)

Search is not implemented for path sources.

type SourceFactory

type SourceFactory interface {
	CreateSource(location *berkshelf.SourceLocation) (CookbookSource, error)
}

SourceFactory creates a CookbookSource from a SourceLocation.

type SupermarketSource

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

SupermarketSource implements CookbookSource for Chef Supermarket API.

func NewSupermarketSource

func NewSupermarketSource(baseURL string) *SupermarketSource

NewSupermarketSource creates a new Supermarket source.

func (*SupermarketSource) DownloadAndExtractCookbook

func (s *SupermarketSource) DownloadAndExtractCookbook(ctx context.Context, cookbook *berkshelf.Cookbook, targetDir string) error

DownloadAndExtractCookbook downloads the cookbook tarball and extracts it to the specified directory.

func (*SupermarketSource) FetchCookbook

func (s *SupermarketSource) FetchCookbook(ctx context.Context, name string, version *berkshelf.Version) (*berkshelf.Cookbook, error)

FetchCookbook downloads the complete cookbook at the specified version.

func (*SupermarketSource) FetchMetadata

func (s *SupermarketSource) FetchMetadata(ctx context.Context, name string, version *berkshelf.Version) (*berkshelf.Metadata, error)

FetchMetadata downloads just the metadata for a cookbook version.

func (*SupermarketSource) GetSourceLocation

func (s *SupermarketSource) GetSourceLocation() *berkshelf.SourceLocation

GetSourceLocation returns the source location for this supermarket source

func (*SupermarketSource) GetSourceType

func (s *SupermarketSource) GetSourceType() string

GetSourceType returns the source type

func (*SupermarketSource) GetSourceURL

func (s *SupermarketSource) GetSourceURL() string

GetSourceURL returns the source URL

func (*SupermarketSource) ListVersions

func (s *SupermarketSource) ListVersions(ctx context.Context, name string) ([]*berkshelf.Version, error)

ListVersions returns all available versions of a cookbook.

func (*SupermarketSource) Name

func (s *SupermarketSource) Name() string

Name returns the name of this source.

func (*SupermarketSource) Priority

func (s *SupermarketSource) Priority() int

Priority returns the priority of this source.

func (*SupermarketSource) Search

func (s *SupermarketSource) Search(ctx context.Context, query string) ([]*berkshelf.Cookbook, error)

Search returns cookbooks matching the query.

func (*SupermarketSource) SetAPIKey

func (s *SupermarketSource) SetAPIKey(key string)

SetAPIKey sets the API key for authenticated requests.

func (*SupermarketSource) SetPriority

func (s *SupermarketSource) SetPriority(priority int)

SetPriority sets the priority of this source.

Jump to

Keyboard shortcuts

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