Documentation
¶
Overview ¶
Package source provides interfaces and implementations for cookbook sources.
Index ¶
- Constants
- Variables
- type ChefServerSource
- func (s *ChefServerSource) DownloadAndExtractCookbook(ctx context.Context, cookbook *berkshelf.Cookbook, targetDir string) error
- func (s *ChefServerSource) FetchCookbook(ctx context.Context, name string, version *berkshelf.Version) (*berkshelf.Cookbook, error)
- func (s *ChefServerSource) FetchMetadata(ctx context.Context, name string, version *berkshelf.Version) (*berkshelf.Metadata, error)
- func (s *ChefServerSource) GetSourceLocation() *berkshelf.SourceLocation
- func (s *ChefServerSource) GetSourceType() string
- func (s *ChefServerSource) GetSourceURL() string
- func (s *ChefServerSource) ListVersions(ctx context.Context, name string) ([]*berkshelf.Version, error)
- func (s *ChefServerSource) Name() string
- func (s *ChefServerSource) Priority() int
- func (s *ChefServerSource) Search(ctx context.Context, query string) ([]*berkshelf.Cookbook, error)
- func (s *ChefServerSource) SetPriority(priority int)
- type CookbookSource
- type ErrCookbookNotFound
- type ErrInvalidMetadata
- type ErrSourceUnavailable
- type ErrVersionNotFound
- type Factory
- func (f *Factory) AddDefaultSource(source CookbookSource)
- func (f *Factory) CreateFromBerksfile(bf *berksfile.Berksfile) (*Manager, error)
- func (f *Factory) CreateFromLocation(location *berkshelf.SourceLocation) (CookbookSource, error)
- func (f *Factory) CreateFromURL(url string) (CookbookSource, error)
- func (f *Factory) CreateSourceForCookbook(cookbook *berksfile.CookbookDef) ([]CookbookSource, error)
- type GitSource
- func (g *GitSource) DownloadAndExtractCookbook(ctx context.Context, cookbook *berkshelf.Cookbook, targetDir string) error
- func (g *GitSource) FetchCookbook(ctx context.Context, name string, version *berkshelf.Version) (*berkshelf.Cookbook, error)
- func (g *GitSource) FetchMetadata(ctx context.Context, name string, version *berkshelf.Version) (*berkshelf.Metadata, error)
- func (g *GitSource) GetBranch() string
- func (g *GitSource) GetRef() string
- func (g *GitSource) GetRevision() string
- func (g *GitSource) GetSourceLocation() *berkshelf.SourceLocation
- func (g *GitSource) GetSourceType() string
- func (g *GitSource) GetSourceURL() string
- func (g *GitSource) GetTag() string
- func (g *GitSource) ListVersions(ctx context.Context, name string) ([]*berkshelf.Version, error)
- func (g *GitSource) Name() string
- func (g *GitSource) Priority() int
- func (g *GitSource) Search(ctx context.Context, query string) ([]*berkshelf.Cookbook, error)
- type Manager
- func (m *Manager) AddSource(source CookbookSource)
- func (m *Manager) FetchCookbook(ctx context.Context, name string, version *berkshelf.Version) (*berkshelf.Cookbook, error)
- func (m *Manager) GetSources() []CookbookSource
- func (m *Manager) ListVersions(ctx context.Context, name string) ([]*berkshelf.Version, error)
- type PathSource
- func (p *PathSource) DownloadAndExtractCookbook(ctx context.Context, cookbook *berkshelf.Cookbook, targetDir string) error
- func (p *PathSource) FetchCookbook(ctx context.Context, name string, version *berkshelf.Version) (*berkshelf.Cookbook, error)
- func (p *PathSource) FetchMetadata(ctx context.Context, name string, version *berkshelf.Version) (*berkshelf.Metadata, error)
- func (p *PathSource) GetSourceLocation() *berkshelf.SourceLocation
- func (p *PathSource) GetSourceType() string
- func (p *PathSource) GetSourceURL() string
- func (p *PathSource) ListVersions(ctx context.Context, name string) ([]*berkshelf.Version, error)
- func (p *PathSource) Name() string
- func (p *PathSource) Priority() int
- func (p *PathSource) ReadMetadata(cookbookPath string) (*berkshelf.Metadata, error)
- func (p *PathSource) ReadMetadataJSON(path string) (*berkshelf.Metadata, error)
- func (p *PathSource) ReadMetadataRB(path string, cookbookPath string) (*berkshelf.Metadata, error)
- func (p *PathSource) Search(ctx context.Context, query string) ([]*berkshelf.Cookbook, error)
- type SourceFactory
- type SupermarketSource
- func (s *SupermarketSource) DownloadAndExtractCookbook(ctx context.Context, cookbook *berkshelf.Cookbook, targetDir string) error
- func (s *SupermarketSource) FetchCookbook(ctx context.Context, name string, version *berkshelf.Version) (*berkshelf.Cookbook, error)
- func (s *SupermarketSource) FetchMetadata(ctx context.Context, name string, version *berkshelf.Version) (*berkshelf.Metadata, error)
- func (s *SupermarketSource) GetSourceLocation() *berkshelf.SourceLocation
- func (s *SupermarketSource) GetSourceType() string
- func (s *SupermarketSource) GetSourceURL() string
- func (s *SupermarketSource) ListVersions(ctx context.Context, name string) ([]*berkshelf.Version, error)
- func (s *SupermarketSource) Name() string
- func (s *SupermarketSource) Priority() int
- func (s *SupermarketSource) Search(ctx context.Context, query string) ([]*berkshelf.Cookbook, error)
- func (s *SupermarketSource) SetAPIKey(key string)
- func (s *SupermarketSource) SetPriority(priority int)
Constants ¶
const PUBLIC_SUPERMARKET = "https://supermarket.chef.io"
Variables ¶
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) 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 ¶
ErrCookbookNotFound is returned when a cookbook cannot be found.
func (*ErrCookbookNotFound) Error ¶
func (e *ErrCookbookNotFound) Error() string
type ErrInvalidMetadata ¶
ErrInvalidMetadata is returned when cookbook metadata is invalid or corrupt.
func (*ErrInvalidMetadata) Error ¶
func (e *ErrInvalidMetadata) Error() string
type ErrSourceUnavailable ¶
type ErrSourceUnavailable struct {
}
ErrSourceUnavailable is returned when a source is temporarily unavailable.
func (*ErrSourceUnavailable) Error ¶
func (e *ErrSourceUnavailable) Error() string
type ErrVersionNotFound ¶
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 (*Factory) AddDefaultSource ¶
func (f *Factory) AddDefaultSource(source CookbookSource)
AddDefaultSource adds a default source to use when no specific source is specified.
func (*Factory) CreateFromBerksfile ¶
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) GetRevision ¶
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 ¶
GetSourceType returns the source type
func (*GitSource) GetSourceURL ¶
GetSourceURL returns the source URL
func (*GitSource) ListVersions ¶
ListVersions returns available versions (tags) from the Git repository.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager coordinates multiple sources.
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
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 ¶
ListVersions returns the versions available in the path 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
ReadMetadataRB parses a metadata.rb file (simplified).
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.