cache

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: MPL-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultRegistryName = "default"
	DefaultRef          = "latest"
	DevRegistryName     = "<<local folder>>"
	DevRef              = "<<none>>"
	DefaultDirPerms     = 0700
)

Variables

This section is empty.

Functions

func AppendRef

func AppendRef(name, ref string) string

AppendRef is a utility function to format a pack name at a specific ref.

func DefaultCachePath

func DefaultCachePath() string

DefaultCachePath returns the default cache path.

func VerifyPackExists

func VerifyPackExists(cfg *PackConfig, errCtx *errors.UIErrorContext, logger logging.Logger) (err error)

VerifyPackExists verifies that a pack exists at the specified path.

Types

type AddOpts

type AddOpts struct {

	// Required name for the registry. Used when managing a registry by a user defined name.
	RegistryName string
	// The well known location of a registry. Used when adding a registry. URL
	// or file directory currently supported.
	Source string
	// Optional target pack. Used when managing a specific pack within a registry.
	PackName string
	// Optional ref of pack or registry at which to add. Ignored if not
	// specifying a git source. Defaults to latest.
	Ref string
	// Optional username for basic auth to a registry that requires authentication.
	Username string
	// Optional password for basic auth to a registry that requires authentication.
	Password string
	// contains filtered or unexported fields
}

AddOpts are the arguments that are required to add a registry or pack to the cache.

func (*AddOpts) AtRef

func (opts *AddOpts) AtRef() string

AtRef fulfills the cacheOperationProvider interface for AddOpts

func (*AddOpts) ForPackName

func (opts *AddOpts) ForPackName() string

ForPackName fulfills the cacheOperationProvider interface for AddOpts

func (*AddOpts) IsLatest

func (opts *AddOpts) IsLatest() bool

IsLatest fulfills the RegistryOptsProviderInterface for AddOpts

func (*AddOpts) IsTarget

func (opts *AddOpts) IsTarget(dirEntry os.DirEntry) bool

IsTarget fulfills the RegistryOptsProviderInterface for AddOpts

func (*AddOpts) PackDir

func (opts *AddOpts) PackDir() string

PackDir fulfills the cacheOperationProvider interface for AddOpts

func (*AddOpts) PackPath

func (opts *AddOpts) PackPath() string

PackPath fulfills the cacheOperationProvider interface for AddOpts

func (*AddOpts) RegistryPath

func (opts *AddOpts) RegistryPath() string

RegistryPath fulfills the cacheOperationProvider interface for AddOpts

type Cache

type Cache struct {

	// ErrorContext stores any errors that were encountered along the way so that
	// error handling can be dealt with in one place.
	ErrorContext *errors.ErrorContext
	// contains filtered or unexported fields
}

Cache encapsulates the state and functionality of a Cache of registries

func NewCache

func NewCache(cfg *CacheConfig) (cache *Cache, err error)

NewCache instantiates a new cache instance with the specified config. If no config is provided, the cache is initialized with default configuration.

func (*Cache) Add

func (c *Cache) Add(opts *AddOpts) (*Registry, error)

Add adds a registry to a cache from the passed config.

func (*Cache) Delete

func (c *Cache) Delete(opts *DeleteOpts) (err error)

Delete deletes a registry from the specified global cache directory. If the name includes a @ref component, only packs matching that ref will be deleted. If a target is specified, only packs matching that target will be deleted. Ref and target are additive.

func (*Cache) Get

func (c *Cache) Get(opts *GetOpts) (registry *Registry, err error)

Get loads a Registry struct and all its packs from a registry path.

func (*Cache) Load

func (c *Cache) Load() (err error)

Load loads a list of registries from a cache path. It assumes each directory in the specified path cache is a registry.

func (*Cache) Packs

func (c *Cache) Packs() (packs []*Pack)

Packs is an accessor for the cached packs contains within the cache instance.

func (*Cache) Registries

func (c *Cache) Registries() []*Registry

Registries is an accessor for the cached registries contain within the cache instance.

type CacheConfig

type CacheConfig struct {
	Path   string
	Eager  bool
	Logger logging.Logger
}

CacheConfig encapsulates the configuration options for a cache instance.

type DeleteOpts

type DeleteOpts struct {

	// Name or alias of the registry the delete operation will be performed against.
	RegistryName string
	// Optional pack name to delete when deleting a specific pack from the cache.
	PackName string
	// Optional ref of pack or registry at which to delete. Ignored it not
	// specifying a git source. Defaults to latest.
	Ref string
	// contains filtered or unexported fields
}

DeleteOpts are the arguments that are required to delete a registry or pack from the cache.

func (*DeleteOpts) AtRef

func (opts *DeleteOpts) AtRef() string

AtRef fulfills the cacheOperationProvider interface for DeleteOpts

func (*DeleteOpts) ForPackName

func (opts *DeleteOpts) ForPackName() string

ForPackName fulfills the cacheOperationProvider interface for DeleteOpts

func (*DeleteOpts) IsLatest

func (opts *DeleteOpts) IsLatest() bool

IsLatest fulfills the RegistryOptsProviderInterface for DeleteOpts

func (*DeleteOpts) IsTarget

func (opts *DeleteOpts) IsTarget(dirEntry os.DirEntry) bool

IsTarget fulfills the RegistryOptsProviderInterface for DeleteOpts

func (*DeleteOpts) PackDir

func (opts *DeleteOpts) PackDir() string

PackDir fulfills the cacheOperationProvider interface for DeleteOpts

func (*DeleteOpts) PackPath

func (opts *DeleteOpts) PackPath() (packPath string)

PackPath fulfills the cacheOperationProvider interface for DeleteOpts

func (*DeleteOpts) RegistryPath

func (opts *DeleteOpts) RegistryPath() string

RegistryPath fulfills the cacheOperationProvider interface for DeleteOpts

type GetOpts

type GetOpts struct {

	// Optional Name or alias of the registry the get operation will be performed
	// against.
	RegistryName string
	// Optional name of pack to get from cache
	PackName string
	// Optional ref ov pack or registry to get from the cache.
	Ref string
	// contains filtered or unexported fields
}

GetOpts are the arguments are required to get a registry or pack from the cache.

func (*GetOpts) AtRef

func (opts *GetOpts) AtRef() string

AtRevision fulfills the cacheOperationProvider interface for GetOpts

func (*GetOpts) ForPackName

func (opts *GetOpts) ForPackName() string

ForPackName fulfills the cacheOperationProvider interface for GetOpts

func (*GetOpts) IsLatest

func (opts *GetOpts) IsLatest() bool

IsLatest fulfills the RegistryOptsProviderInterface for GetOpts

func (*GetOpts) IsTarget

func (opts *GetOpts) IsTarget(dirEntry os.DirEntry) bool

IsTarget fulfills the RegistryOptsProviderInterface for GetOpts

func (*GetOpts) PackDir

func (opts *GetOpts) PackDir() string

PackDir fulfills the cacheOperationProvider interface for GetOpts

func (*GetOpts) PackPath

func (opts *GetOpts) PackPath() string

PackPath fulfills the cacheOperationProvider interface for GetOpts

func (*GetOpts) RegistryPath

func (opts *GetOpts) RegistryPath() string

RegistryPath fulfills the cacheOperationProvider interface for GetOpts

type Pack

type Pack struct {
	Ref string
	*pack.Pack
}

Pack wraps a pack.Pack add adds the local cache ref. Useful for showing the registry in the global cache differentiated from the pack metadata.

type PackConfig

type PackConfig struct {
	Registry   string
	Name       string
	Ref        string
	Path       string
	SourcePath string
}

PackConfig represents the common configuration required by all packs. Used primarily by the cli package but should

func (*PackConfig) Init

func (cfg *PackConfig) Init()

type Registry

type Registry struct {
	// Name as defined by the user
	Name string `json:"name,omitempty"`
	// Source URL of the registry
	Source string `json:"source,omitempty"`
	// Ref is a reference of the registry as specified by the user (may be "latest"
	// or an actual git ref)
	Ref string `json:"ref,omitempty"`
	// LocalRef is a reference to the git SHA that we have available locally
	LocalRef string  `json:"local_ref,omitempty"`
	Packs    []*Pack `json:"-"`
}

Registry represents a registry definition from the global cache.

Jump to

Keyboard shortcuts

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