utils

package
v1.8.1 Latest Latest
Warning

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

Go to latest
Published: May 7, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HangarGitHubURL         = "https://github.com/cnrancher/hangar"
	DockerHubRegistry       = "docker.io"
	CacheCloneRepoDirectory = "charts-repo-cache"
	MaxWorkerNum            = 20
	MinWorkerNum            = 1
)

Variables

View Source
var (
	ErrVersionIsEmpty      = errors.New("version is empty string")
	ErrNoAvailableImage    = errors.New("no available image for specified arch and os")
	ErrIsSigstoreSignature = errors.New("image is a sigstore signature")
)
View Source
var (
	Version   = "v1.8.1"
	GitCommit = ""
)

Functions

func AddSourceToImage

func AddSourceToImage(
	imagesSet map[string]map[string]bool,
	image string,
	sources ...string,
)

AddSourceToImage adds image into map[image][source]bool

func Base64

func Base64(s string) string

func CheckFileExistsPrompt added in v1.7.1

func CheckFileExistsPrompt(
	ctx context.Context, name string, autoYes bool,
) error

func ConstructRegistry

func ConstructRegistry(image, registryOverride string) string

ConstructRegistry will re-construct the image url:

If `registryOverride` is empty string, example:

nginx --> docker.io/nginx (add docker.io prefix)
reg.io/nginx --> reg.io/nginx (nothing changed)
reg.io/user/nginx --> reg.io/user/nginx (nothing changed)

If `registryOverride` set, example:

nginx --> ${registryOverride}/nginx (add ${registryOverride} prefix)
reg.io/nginx --> ${registryOverride}/nginx (set registry ${registryOverride})
reg.io/user/nginx --> ${registryOverride}/user/nginx (same as above)

func CopyPolicy added in v1.7.0

func CopyPolicy(src *signature.Policy) (*signature.Policy, error)

func CopySystemContext added in v1.7.0

func CopySystemContext(src *types.SystemContext) *types.SystemContext

func DecodeBase64

func DecodeBase64(s string) (string, error)

func DetectURL added in v1.8.0

func DetectURL(
	ctx context.Context, s string, insecure bool,
) (string, *http.Response, error)

DetectURL detects whether the server is using HTTPS or HTTP (if in insecure mode) User need to call resp.Body.Close after usage.

func EnsureSemverValid

func EnsureSemverValid(v string) (string, error)

func GetImageName added in v1.5.0

func GetImageName(image string) string

GetImageName gets the image name, example:

nginx:latest -> nginx
reg.io/nginx:latest -> nginx
library/nginx:latest -> nginx
reg.io/library/nginx -> nginx

func GetImageTag added in v1.7.0

func GetImageTag(image string) string

GetImageTag gets the image tag, example:

nginx:latest -> latest
nginx:1.22 -> 1.22
reg.io/nginx:1.22 -> 1.22
library/nginx -> latest
reg.io/library/nginx -> latest

func GetProjectName

func GetProjectName(image string) string

GetProjectName gets the project name of the image, example:

nginx -> "library"
docker.io/nginx -> "library"
library/nginx -> "library"
docker.io/library/nginx -> "library"

func GetRegistryName

func GetRegistryName(image string) string

GetRegistryName gets the registry name of the image, example:

nginx -> docker.io
reg.io/nginx -> reg.io
library/nginx -> docker.io
reg.io/library/nginx -> reg.io

func HTTPClientDo added in v1.7.2

func HTTPClientDo(
	ctx context.Context, client *http.Client, req *http.Request,
) (*http.Response, error)

func HTTPClientDoWithRetry added in v1.7.1

func HTTPClientDoWithRetry(
	ctx context.Context, client *http.Client, req *http.Request,
) (*http.Response, error)

func HangarCacheDir added in v1.8.0

func HangarCacheDir() string

Get the hangar cache dir.

The default cache dir is `${HOME}/.cache/hangar/<random>`.

func MergeImageSourceSet added in v1.7.1

func MergeImageSourceSet(a, b map[string]map[string]bool)

Merge map[image]map[source]true from b into a

func MergeSets added in v1.7.1

func MergeSets(a, b map[string]bool)

Merge map[string]true from b into a

func PrintObject added in v1.7.0

func PrintObject(a any) string

func ReadPassword added in v1.8.0

func ReadPassword(ctx context.Context) ([]byte, error)

func ReplaceProjectName

func ReplaceProjectName(image, project string) string

ReplaceProjectName will replace the image project name:

If `project` is empty string, the project name will be removed:

nginx --> nginx (nothing changed)
reg.io/nginx --> reg.io/nginx (nothing changed)
user/nginx --> nginx (remove project name)
reg.io/user/nginx --> reg.io/nginx (remove project name)

If `project` set, example:

nginx --> ${project}/nginx (add project name)
user/nginx --> ${project}/nginx (replace project name)
reg.io/nginx --> reg.io/${project}/nginx
reg.io/user/nginx --> reg.io/${project}/nginx

func Scanf added in v1.7.0

func Scanf(ctx context.Context, format string, a ...any) (int, error)

func SemverCompare

func SemverCompare(a, b string) (int, error)

SemverCompare compares two semvers

The result will be 0 if a == b, -1 if a < b, or +1 if a > b.

func SemverMajorEqual

func SemverMajorEqual(a, b string) bool

func SemverMajorMinorEqual

func SemverMajorMinorEqual(a, b string) bool

func Sha256Sum

func Sha256Sum(s string) string

func SystemContextWithSharedBlobDir added in v1.7.0

func SystemContextWithSharedBlobDir(sysctx *types.SystemContext, dir string) *types.SystemContext

func SystemContextWithTLSVerify added in v1.7.0

func SystemContextWithTLSVerify(sysctx *types.SystemContext, tlsVerify bool) *types.SystemContext

func ToObj

func ToObj(data interface{}, into interface{}) error

func TrivyCacheDir added in v1.8.0

func TrivyCacheDir() string

Get the teivy cache dir for trivy databases.

Types

This section is empty.

Jump to

Keyboard shortcuts

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