registry

package
v0.13.1 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2018 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultAPIVersion is the default version of the registry API.
	DefaultAPIVersion = "0.2.0"
	// DefaultKind is the default kind of the registry API.
	DefaultKind = "ksonnet.io/registry"
)

Variables

This section is empty.

Functions

func CacheDependency

func CacheDependency(a app.App, checker InstalledChecker, d pkg.Descriptor, customName string, force bool, httpClient *http.Client) (*app.LibraryConfig, error)

CacheDependency vendors registry dependencies. TODO: create unit tests for this once mocks for this package are worked out.

func DefaultYAMLData

func DefaultYAMLData(r Registry) ([]byte, error)

DefaultYAMLData generates the contents for a registry's spec.

Types

type Fs

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

Fs is a registry based on a local filesystem.

func NewFs

func NewFs(a app.App, registryRef *app.RegistryConfig) (*Fs, error)

NewFs creates an instance of Fs. Assign a name to the RegistryConfig if you want the Fs to know it's name.

func (*Fs) CacheRoot

func (fs *Fs) CacheRoot(name, path string) (string, error)

CacheRoot combines the path with the registry name.

func (*Fs) FetchRegistrySpec

func (fs *Fs) FetchRegistrySpec() (*Spec, error)

FetchRegistrySpec fetches the registry spec.

func (*Fs) MakeRegistryConfig added in v0.12.0

func (fs *Fs) MakeRegistryConfig() *app.RegistryConfig

MakeRegistryConfig returns an app registry ref spec.

func (*Fs) Name

func (fs *Fs) Name() string

Name is the registry name.

func (*Fs) Protocol

func (fs *Fs) Protocol() Protocol

Protocol is the registry protocol.

func (*Fs) RegistrySpecDir

func (fs *Fs) RegistrySpecDir() string

RegistrySpecDir is the registry directory.

func (*Fs) RegistrySpecFilePath

func (fs *Fs) RegistrySpecFilePath() string

RegistrySpecFilePath is the path for the registry.yaml

func (*Fs) ResolveLibrary

func (fs *Fs) ResolveLibrary(partName, partAlias, libRefSpec string, onFile ResolveFile, onDir ResolveDirectory) (*parts.Spec, *app.LibraryConfig, error)

ResolveLibrary fetches the part and creates a parts spec and library ref spec.

func (*Fs) ResolveLibrarySpec

func (fs *Fs) ResolveLibrarySpec(partName, libRefSpec string) (*parts.Spec, error)

ResolveLibrarySpec returns a resolved spec for a part. `libRefSpec` is ignored.

func (*Fs) SetURI added in v0.12.0

func (fs *Fs) SetURI(uri string) error

SetURI implements registry.Setter. It sets the URI for the registry.

func (*Fs) URI

func (fs *Fs) URI() string

URI is the registry URI.

func (*Fs) ValidateURI added in v0.12.0

func (fs *Fs) ValidateURI(uri string) (bool, error)

ValidateURI implements registry.Validator. A URI is valid if:

  • It is a valid URI (RFC 3986)
  • It points to an existing directory on disk
  • That directory contains a `registry.yaml` file

type FsRemoveAller added in v0.13.0

type FsRemoveAller interface {
	// RemoveAll removes a directory path and any children it contains. It
	// does not fail if the path does not exist (return nil).
	RemoveAll(path string) error
}

FsRemoveAller Subset of afero.Fs - just remove a directory

type GarbageCollector added in v0.13.0

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

GarbageCollector removes vendored packages that are no longer needed

func NewGarbageCollector added in v0.13.0

func NewGarbageCollector(fs afero.Fs, pm vendorPathResolver, root string) GarbageCollector

NewGarbageCollector constructs a GarbageCollector

func (GarbageCollector) RemoveOrphans added in v0.13.0

func (gc GarbageCollector) RemoveOrphans(d pkg.Descriptor) error

RemoveOrphans removes vendored packages that have been orphaned

type GitHub

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

GitHub is a Github Registry

func NewGitHub

func NewGitHub(a app.App, registryRef *app.RegistryConfig, opts ...GitHubOpt) (*GitHub, error)

NewGitHub creates an instance of GitHub.

func (*GitHub) CacheRoot

func (gh *GitHub) CacheRoot(name, path string) (string, error)

CacheRoot returns the root for caching - it removes any leading path segments from a provided path, leaving just the relative path under the registry name. Example:

uri:    github.com/ksonnet/parts/tree/master/long/path/incubator
path:   long/path/incubator/parts.yaml
output: incubator/parts.yaml

func (*GitHub) FetchRegistrySpec

func (gh *GitHub) FetchRegistrySpec() (*Spec, error)

FetchRegistrySpec fetches the registry spec (registry.yaml, inventory of packages) This inventory may have been previously cached on disk. If the cache is not stale, it will be used. Otherwise, the spec is fetched from the remote repository.

func (*GitHub) MakeRegistryConfig added in v0.12.0

func (gh *GitHub) MakeRegistryConfig() *app.RegistryConfig

MakeRegistryConfig returns an app registry ref spec.

func (*GitHub) Name

func (gh *GitHub) Name() string

Name is the registry name.

func (*GitHub) Protocol

func (gh *GitHub) Protocol() Protocol

Protocol is the registry protocol.

func (*GitHub) RegistrySpecDir

func (gh *GitHub) RegistrySpecDir() string

RegistrySpecDir is the registry directory.

func (*GitHub) RegistrySpecFilePath

func (gh *GitHub) RegistrySpecFilePath() string

RegistrySpecFilePath is the path for the registry.yaml

func (*GitHub) ResolveLibrary

func (gh *GitHub) ResolveLibrary(partName, partAlias, libRefSpec string, onFile ResolveFile, onDir ResolveDirectory) (*parts.Spec, *app.LibraryConfig, error)

ResolveLibrary fetches the part and creates a parts spec and library ref spec.

func (*GitHub) ResolveLibrarySpec

func (gh *GitHub) ResolveLibrarySpec(partName, libRefSpec string) (*parts.Spec, error)

ResolveLibrarySpec returns a resolved spec for a part.

func (*GitHub) SetURI added in v0.12.0

func (gh *GitHub) SetURI(uri string) error

SetURI implements registry.Setter. It sets the URI for the registry.

func (*GitHub) URI

func (gh *GitHub) URI() string

URI is the registry URI.

func (*GitHub) ValidateURI added in v0.12.0

func (gh *GitHub) ValidateURI(uri string) (bool, error)

ValidateURI implements registry.Validator. A URI is valid if:

  • It is a valid URI (RFC 3986)
  • It points to GitHub (Enterprise not supported at this time)
  • It points to a valid tree in a GitHub repository
  • That tree contains a `registry.yaml` file
  • It currently exists (a HEAD request is sent over the network)

type GitHubOpt

type GitHubOpt func(*GitHub)

GitHubOpt is an option for configuring GitHub.

func GitHubClient

func GitHubClient(c github.GitHub) GitHubOpt

GitHubClient is an option for the setting a github client.

type Helm added in v0.12.0

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

Helm is a Helm repository.

func NewHelm added in v0.12.0

func NewHelm(a app.App, registryRef *app.RegistryConfig, rc helm.RepositoryClient, ua archive.Unarchiver) (*Helm, error)

NewHelm creates an instance of Helm.

func (*Helm) CacheRoot added in v0.12.0

func (h *Helm) CacheRoot(name string, relPath string) (string, error)

CacheRoot returns the root for caching by combining the path with the registry name.

func (*Helm) FetchRegistrySpec added in v0.12.0

func (h *Helm) FetchRegistrySpec() (*Spec, error)

FetchRegistrySpec fetches the registry spec. This method returns an unmarshalled version of registry.yaml

func (*Helm) MakeRegistryConfig added in v0.12.0

func (h *Helm) MakeRegistryConfig() *app.RegistryConfig

MakeRegistryConfig returns app registry ref spec.

func (*Helm) Name added in v0.12.0

func (h *Helm) Name() string

Name is the registry name.

func (*Helm) Protocol added in v0.12.0

func (h *Helm) Protocol() Protocol

Protocol is the registry protocol.

func (*Helm) RegistrySpecDir added in v0.12.0

func (h *Helm) RegistrySpecDir() string

RegistrySpecDir is the registry directory.

func (*Helm) RegistrySpecFilePath added in v0.12.0

func (h *Helm) RegistrySpecFilePath() string

RegistrySpecFilePath is the path for the registry.yaml NOTE: this function appears to be github registry specific and may not need to be a part of the interface.

func (*Helm) ResolveLibrary added in v0.12.0

func (h *Helm) ResolveLibrary(partName string, partAlias string, version string, onFile ResolveFile, onDir ResolveDirectory) (*parts.Spec, *app.LibraryConfig, error)

ResolveLibrary fetches the part and creates a parts spec and library ref spec.

func (*Helm) ResolveLibrarySpec added in v0.12.0

func (h *Helm) ResolveLibrarySpec(partName, version string) (*parts.Spec, error)

ResolveLibrarySpec returns a resolved spec for a part.

func (*Helm) SetURI added in v0.12.0

func (h *Helm) SetURI(uri string) error

SetURI implements registry.Setter. It sets the URI for the registry.

func (*Helm) URI added in v0.12.0

func (h *Helm) URI() string

URI is the registry URI.

func (*Helm) Update added in v0.12.0

func (h *Helm) Update(version string) (string, error)

Update implements registry.Updater

func (*Helm) ValidateURI added in v0.12.0

func (h *Helm) ValidateURI(uri string) (bool, error)

ValidateURI implements registry.Validator. A URI is valid if:

  • It is a valid URI (RFC 3986)
  • It is an absolute URI or an absolute path

type InstalledChecker added in v0.12.0

type InstalledChecker interface {
	// IsInstalled checks whether a package is installed.
	// Supports fuzzy searches: Name, Name/Version, Registry/Name/Version, Registry/Version
	IsInstalled(d pkg.Descriptor) (bool, error)
}

InstalledChecker checks if a package is installed, based on app config.

type LibraryConfig added in v0.12.0

type LibraryConfig struct {
	Version string `json:"version"`
	Path    string `json:"path"`
}

LibraryConfig is library reference.

type LibraryConfigs added in v0.12.0

type LibraryConfigs map[string]*LibraryConfig

LibraryConfigs maps LibraryConfigs to a name.

type LibraryResolver added in v0.12.0

type LibraryResolver interface {
	ResolveLibrary(libID, libAlias, version string, onFile ResolveFile, onDir ResolveDirectory) (*parts.Spec, *app.LibraryConfig, error)
}

LibraryResolver fetches library (package) contents from a registry

type LibrarySpecResolver added in v0.12.0

type LibrarySpecResolver interface {
	ResolveLibrarySpec(libID, libRefSpec string) (*parts.Spec, error)
}

LibrarySpecResolver fetches metadata for a library.

type PackageManager added in v0.12.0

type PackageManager interface {
	InstalledChecker

	// Find finds a package by name. Package names have the format `<registry>/<library>@<version>`.
	// Remote registries may be consulted if the package is not installed locally.
	Find(pkg.Descriptor) (pkg.Package, error)

	// Packages lists packages.
	Packages() ([]pkg.Package, error)

	// PackagesForEnv returns a list of Packages defined in the application, from the context
	// of the specified environment.
	PackagesForEnv(e *app.EnvironmentConfig) ([]pkg.Package, error)

	// RemotePackages returns a list of remote packages.
	RemotePackages() ([]pkg.Package, error)

	// Prototypes lists prototypes.
	Prototypes() (prototype.Prototypes, error)

	// PackageEnvironments returns a list of environments a package is installed in.
	PackageEnvironments(pkg pkg.Package) ([]*app.EnvironmentConfig, error)

	// VendorPath returns the local path a package would be vendored at
	VendorPath(pkg.Descriptor) (string, error)
}

PackageManager is a package manager.

func NewPackageManager added in v0.12.0

func NewPackageManager(a app.App, opts ...PackageManagerOpt) PackageManager

NewPackageManager creates an instance of PackageManager.

type PackageManagerOpt added in v0.13.0

type PackageManagerOpt func(*packageManager)

PackageManagerOpt configures a package mangager

func HTTPClientOpt added in v0.13.0

func HTTPClientOpt(httpClient *http.Client) PackageManagerOpt

HTTPClientOpt configures a packageManager with an http.Client

type Protocol

type Protocol string

Protocol is the protocol for a registry.

const (
	// ProtocolFilesystem is the protocol for file system based registries.
	ProtocolFilesystem Protocol = "fs"
	// ProtocolGitHub is the protocol for GitHub based registries.
	ProtocolGitHub Protocol = "github"
	// ProtocolHelm is the protocol for Helm based registries.
	ProtocolHelm Protocol = "helm"
	// ProtocolInvalid is an invalid protocol.
	ProtocolInvalid Protocol = "invalid"
)

func (Protocol) String

func (p Protocol) String() string

type Registry

type Registry interface {
	RegistrySpecDir() string
	RegistrySpecFilePath() string
	LibrarySpecResolver
	LibraryResolver
	Name() string
	Protocol() Protocol
	URI() string
	CacheRoot(name, relPath string) (string, error)

	Validator
	Setter
}

Registry is a Registry

func List

func List(ksApp app.App, httpClient *http.Client) ([]Registry, error)

List returns a list of alphabetically sorted Registries.

func Locate

func Locate(a app.App, spec *app.RegistryConfig, httpClient *http.Client) (Registry, error)

Locate locates a registry given a spec.

type ResolveDirectory

type ResolveDirectory func(relPath string) error

ResolveDirectory resolves directories when searching a part.

type ResolveFile

type ResolveFile func(relPath string, contents []byte) error

ResolveFile resolves files found when searching a part.

type Setter added in v0.12.0

type Setter interface {
	SetURI(uri string) (err error)
	MakeRegistryConfig() *app.RegistryConfig
	SpecFetcher
}

Setter is an interface for updating an existing registry

type Spec

type Spec struct {
	APIVersion string         `json:"apiVersion"`
	Kind       string         `json:"kind"`
	Version    string         `json:"version"`
	Libraries  LibraryConfigs `json:"libraries"`
}

Spec describes how a registry is stored.

func Add

func Add(a app.App, protocol Protocol, name string, uri string, isOverride bool, httpClient *http.Client) (*Spec, error)

Add adds a registry with `name`, `protocol`, and `uri` to the current ksonnet application.

func Unmarshal

func Unmarshal(bytes []byte) (*Spec, error)

Unmarshal unmarshals bytes to a Spec.

func (*Spec) Marshal

func (s *Spec) Marshal() ([]byte, error)

Marshal marshals a Spec to YAML.

func (*Spec) UnmarshalJSON added in v0.12.0

func (s *Spec) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface. We implement some compatibility conversions.

type SpecFetcher added in v0.12.0

type SpecFetcher interface {
	// FetchRegistrySpec fetches the registry spec (registry.yaml, inventory of packages)
	FetchRegistrySpec() (*Spec, error)
}

SpecFetcher fetches registry metadata

type Specs

type Specs []*Spec

Specs is a slice of *Spec.

type Validator added in v0.12.0

type Validator interface {
	ValidateURI(uri string) (bool, error)
}

Validator is an interface for validating a registry URI

Directories

Path Synopsis
Code generated by mockery v1.0.0.
Code generated by mockery v1.0.0.

Jump to

Keyboard shortcuts

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