downloader

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: Apache-2.0 Imports: 22 Imported by: 7

Documentation

Overview

Copyright 2022 The KCL Authors. All rights reserved.

Index

Constants

View Source
const DEP_PATTERN = "%s = %s"
View Source
const GIT_BRANCH_FLAG = "branch"
View Source
const GIT_BRANCH_PATTERN = "branch = \"%s\""
View Source
const GIT_COMMIT_FLAG = "commit"
View Source
const GIT_COMMIT_PATTERN = "commit = \"%s\""
View Source
const GIT_PACKAGE = "package = \"%s\""
View Source
const GIT_PACKAGE_FLAG = "package"
View Source
const GIT_URL_FLAG = "git"
View Source
const GIT_URL_PATTERN = "git = \"%s\""
View Source
const LOCAL_PATH_FLAG = "path"
View Source
const LOCAL_PATH_PATTERN = "path = %s"
View Source
const NEWLINE = "\n"
View Source
const OCI_URL_PATTERN = "oci = \"%s\""
View Source
const SEPARATOR = ", "
View Source
const SOURCE_PATTERN = "{ %s }"
View Source
const SPEC_PATTERN = "%s = %q"
View Source
const TAG_FLAG = "tag"
View Source
const TAG_PATTERN = "tag = \"%s\""
View Source
const VERSION_PATTERN = "version = \"%s\""

Variables

View Source
var ErrNotFoundAndOffline = errors.New("not found and offline")

Functions

func FindPackageByModSpec added in v0.11.0

func FindPackageByModSpec(root string, modSpec *ModSpec) (string, error)

func ParseSourceUrlFrom added in v0.9.0

func ParseSourceUrlFrom(sourceStr string, settings *settings.Settings) (*url.URL, error)

Types

type CredClient added in v0.9.1

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

CredClient is the client to get the credentials.

func LoadCredentialFile added in v0.9.1

func LoadCredentialFile(filepath string) (*CredClient, error)

LoadCredentialFile loads the credential file and return the CredClient.

func (*CredClient) Credential added in v0.9.1

func (cred *CredClient) Credential(hostName string) (*remoteauth.Credential, error)

Credential will reture the credential info cache in CredClient

func (*CredClient) GetAuthClient added in v0.9.1

func (cred *CredClient) GetAuthClient() *dockerauth.Client

GetAuthClient returns the auth client.

type DepDownloader

type DepDownloader struct {
	*OciDownloader
	*GitDownloader
}

DepDownloader is the downloader for the package. Only support the OCI and git source.

func NewOciDownloader

func NewOciDownloader(platform string) *DepDownloader

func (*DepDownloader) Download

func (d *DepDownloader) Download(opts *DownloadOptions) error

func (*DepDownloader) LatestVersion added in v0.11.0

func (d *DepDownloader) LatestVersion(opts *DownloadOptions) (string, error)

type DownloadOptions

type DownloadOptions struct {
	// LocalPath is the local path to download the package.
	LocalPath string
	// CachePath is the cache path to download the package.
	CachePath string
	// EnableCache is the flag to enable the cache.
	// If `EnableCache` is false, this will not result in increasing disk usage.
	EnableCache bool
	// Source is the source of the package. including git, oci, local.
	Source Source
	// Settings is the default settings and authrization information.
	Settings settings.Settings
	// LogWriter is the writer to write the log.
	LogWriter io.Writer

	// InsecureSkipTLSverify is the flag to skip the verification of the certificate.
	InsecureSkipTLSverify bool
	// Offline is the flag to download the package offline.
	Offline bool
	// contains filtered or unexported fields
}

DownloadOptions is the options for downloading a package.

func NewDownloadOptions

func NewDownloadOptions(opts ...Option) *DownloadOptions

type Downloader

type Downloader interface {
	Download(opts *DownloadOptions) error
	// Get the latest version of the remote source
	// For the git source, it will return the latest commit
	// For the OCI source, it will return the latest tag
	LatestVersion(opts *DownloadOptions) (string, error)
}

Downloader is the interface for downloading a package.

type Git added in v0.9.0

type Git struct {
	Url     string `toml:"url,omitempty"`
	Branch  string `toml:"branch,omitempty"`
	Commit  string `toml:"commit,omitempty"`
	Tag     string `toml:"git_tag,omitempty"`
	Version string `toml:"version,omitempty"`
	Package string `toml:"package,omitempty"`
}

Git is the package source from git registry.

func (*Git) FromString added in v0.9.0

func (git *Git) FromString(gitStr string) error

func (*Git) GetPackage added in v0.10.0

func (git *Git) GetPackage() string

func (*Git) GetRef added in v0.11.0

func (g *Git) GetRef() string

func (*Git) GetValidGitReference added in v0.9.0

func (git *Git) GetValidGitReference() (string, error)

GetValidGitReference will get the valid git reference from git source. Only one of branch, tag or commit is allowed.

func (*Git) Hash added in v0.11.0

func (g *Git) Hash() (string, error)

func (*Git) MarshalTOML added in v0.9.0

func (git *Git) MarshalTOML() string

func (*Git) NoRef added in v0.11.0

func (g *Git) NoRef() bool

If the git source has no reference, return true.

func (*Git) ToFilePath added in v0.9.0

func (git *Git) ToFilePath() (string, error)

func (*Git) ToString added in v0.9.0

func (git *Git) ToString() (string, error)

func (*Git) UnmarshalModTOML added in v0.9.0

func (git *Git) UnmarshalModTOML(data interface{}) error

type GitDownloader

type GitDownloader struct{}

GitDownloader is the downloader for the git source.

func (*GitDownloader) Download

func (d *GitDownloader) Download(opts *DownloadOptions) error

func (*GitDownloader) LatestVersion added in v0.11.0

func (d *GitDownloader) LatestVersion(opts *DownloadOptions) (string, error)

type Local added in v0.9.0

type Local struct {
	Path string `toml:"path,omitempty"`
}

func (*Local) FindRootPath added in v0.9.0

func (local *Local) FindRootPath() (string, error)

func (*Local) FromString added in v0.9.0

func (local *Local) FromString(localStr string) error

func (*Local) Hash added in v0.11.0

func (l *Local) Hash() (string, error)

func (*Local) IsDir added in v0.9.0

func (local *Local) IsDir() bool

func (*Local) IsLocalKPath added in v0.9.0

func (local *Local) IsLocalKPath() bool

func (*Local) IsLocalTarPath added in v0.9.0

func (local *Local) IsLocalTarPath() bool

func (*Local) IsLocalTgzPath added in v0.9.1

func (local *Local) IsLocalTgzPath() bool

func (*Local) MarshalTOML added in v0.9.0

func (local *Local) MarshalTOML() string

func (*Local) ToFilePath added in v0.9.0

func (local *Local) ToFilePath() (string, error)

func (*Local) ToString added in v0.9.0

func (local *Local) ToString() (string, error)

func (*Local) UnmarshalModTOML added in v0.9.0

func (local *Local) UnmarshalModTOML(data interface{}) error

type ModSpec added in v0.11.0

type ModSpec struct {
	Name    string
	Version string
	Alias   string
}

The KCL module.

func (*ModSpec) FromString added in v0.11.0

func (ps *ModSpec) FromString(registryStr string) error

func (*ModSpec) IsNil added in v0.11.0

func (p *ModSpec) IsNil() bool

IsNil returns true if the ModSpec is nil.

func (*ModSpec) MarshalTOML added in v0.11.0

func (ps *ModSpec) MarshalTOML() string

func (*ModSpec) ToString added in v0.11.0

func (mod *ModSpec) ToString() string

func (*ModSpec) UnmarshalModTOML added in v0.11.0

func (ps *ModSpec) UnmarshalModTOML(data interface{}) error

type Oci added in v0.9.0

type Oci struct {
	Reg  string `toml:"reg,omitempty"`
	Repo string `toml:"repo,omitempty"`
	Tag  string `toml:"oci_tag,omitempty"`
}

func (*Oci) FromString added in v0.9.0

func (oci *Oci) FromString(ociStr string) error

func (*Oci) GetRef added in v0.11.0

func (o *Oci) GetRef() string

func (*Oci) Hash added in v0.11.0

func (o *Oci) Hash() (string, error)

func (*Oci) IntoOciUrl deprecated added in v0.9.0

func (oci *Oci) IntoOciUrl() string

Deprecated: Use ToString instead

func (*Oci) MarshalTOML added in v0.9.0

func (oci *Oci) MarshalTOML() string

func (*Oci) NoRef added in v0.11.0

func (o *Oci) NoRef() bool

If the OCI source has no reference, return true. TODO: add digest support.

func (*Oci) ToFilePath added in v0.9.0

func (oci *Oci) ToFilePath() (string, error)

func (*Oci) ToString added in v0.9.0

func (oci *Oci) ToString() (string, error)

func (*Oci) UnmarshalModTOML added in v0.9.0

func (oci *Oci) UnmarshalModTOML(data interface{}) error

type OciDownloader

type OciDownloader struct {
	Platform string
}

OciDownloader is the downloader for the OCI source.

func (*OciDownloader) Download

func (d *OciDownloader) Download(opts *DownloadOptions) error

func (*OciDownloader) LatestVersion added in v0.11.0

func (d *OciDownloader) LatestVersion(opts *DownloadOptions) (string, error)

type Option

type Option func(*DownloadOptions)

func WithCachePath added in v0.10.0

func WithCachePath(cachePath string) Option

func WithCredsClient added in v0.9.1

func WithCredsClient(credsClient *CredClient) Option

func WithEnableCache added in v0.10.0

func WithEnableCache(enableCache bool) Option

func WithInsecureSkipTLSverify added in v0.10.0

func WithInsecureSkipTLSverify(insecureSkipTLSverify bool) Option

func WithLocalPath

func WithLocalPath(localPath string) Option

func WithLogWriter

func WithLogWriter(logWriter io.Writer) Option

func WithOffline added in v0.11.0

func WithOffline(offline bool) Option

func WithSettings

func WithSettings(settings settings.Settings) Option

func WithSource

func WithSource(source Source) Option

type Platform

type Platform struct {
	PlatformSpec string
	Platform     *v1.Platform
}

Platform option struct.

type Source added in v0.9.0

type Source struct {
	ModSpec *ModSpec `toml:"-"`
	*Git
	*Oci
	*Local `toml:"-"`
}

Source is the module source. It can be from git, oci, local path. `ModSpec` is used to represent the module in the source. If there are more than one module from the source, use `ModSpec` to specify the module. If the `ModSpec` is nil, it means the source is one module.

func NewSourceFromStr added in v0.9.0

func NewSourceFromStr(sourceStr string) (*Source, error)

func (*Source) CachePath added in v0.11.0

func (s *Source) CachePath(root string) string

func (*Source) FindRootPath added in v0.9.0

func (source *Source) FindRootPath() (string, error)

func (*Source) FromString added in v0.9.0

func (source *Source) FromString(sourceStr string) error

func (*Source) Hash added in v0.11.0

func (s *Source) Hash() (string, error)

func (*Source) IsLocalPath added in v0.9.0

func (source *Source) IsLocalPath() bool

func (*Source) IsLocalPkg added in v0.10.0

func (source *Source) IsLocalPkg() bool

If the source is a local path, check if it is a real local package(a directory with kcl.mod file).

func (*Source) IsLocalTarPath added in v0.9.0

func (source *Source) IsLocalTarPath() bool

func (*Source) IsLocalTgzPath added in v0.9.1

func (source *Source) IsLocalTgzPath() bool

func (*Source) IsNilSource added in v0.11.0

func (source *Source) IsNilSource() bool

func (*Source) IsPackaged added in v0.9.0

func (source *Source) IsPackaged() bool

func (*Source) IsRemote added in v0.9.1

func (source *Source) IsRemote() bool

func (*Source) LocalPath added in v0.11.0

func (s *Source) LocalPath(root string) string

func (*Source) MarshalTOML added in v0.9.0

func (source *Source) MarshalTOML() string

func (*Source) SpecOnly added in v0.11.0

func (s *Source) SpecOnly() bool

func (*Source) ToFilePath added in v0.9.0

func (source *Source) ToFilePath() (string, error)

func (*Source) ToString added in v0.9.0

func (source *Source) ToString() (string, error)

func (*Source) Type added in v0.11.0

func (s *Source) Type() string

func (*Source) UnmarshalModTOML added in v0.9.0

func (source *Source) UnmarshalModTOML(data interface{}) error

Jump to

Keyboard shortcuts

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