util

package
v0.42.3 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package util contains internal utility tools used in imgpkg

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildDefaultUploadTagRef

func BuildDefaultUploadTagRef(item WithDigest, importRepo regname.Repository) (regname.Tag, error)

BuildDefaultUploadTagRef Builds a tag from the digest Algorithm and Digest

func Retry

func Retry(doFunc func() error) error

Types

type BufferLogger

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

BufferLogger write logs to a buffer

func NewBufferLogger

func NewBufferLogger(buf *bytes.Buffer) *BufferLogger

NewBufferLogger creates a new BufferLogger

func (*BufferLogger) Logf

func (b *BufferLogger) Logf(msg string, args ...interface{})

Logf writes log to the buffer

type DefaultTagGenerator

type DefaultTagGenerator struct{}

DefaultTagGenerator implements GenerateTag and generates default tag

func (DefaultTagGenerator) GenerateTag

func (tagGen DefaultTagGenerator) GenerateTag(item imagedigest.DigestWrap, importRepo regname.Repository) (regname.Tag, error)

GenerateTag generates default tag

type LevelLogger

type LevelLogger struct {
	LogLevel LogLevel
	// contains filtered or unexported fields
}

LevelLogger allows specifying a log level to a ui.UI

func NewIndentedLevelLogger

func NewIndentedLevelLogger(logger LoggerWithLevels) *LevelLogger

NewIndentedLevelLogger creates a new logger with levels and indented by 2 spaces

func NewNoopLevelLogger

func NewNoopLevelLogger() *LevelLogger

NewNoopLevelLogger will not print anything

func NewUILevelLogger

func NewUILevelLogger(level LogLevel, logger Logger) *LevelLogger

NewUILevelLogger is a LevelLogger constructor, wrapping a ui.UI with a specific log level

func (LevelLogger) Debugf

func (l LevelLogger) Debugf(msg string, args ...interface{})

Debugf used to log debug related messages

func (LevelLogger) Errorf

func (l LevelLogger) Errorf(msg string, args ...interface{})

Errorf used to log error related messages

func (LevelLogger) Level

func (l LevelLogger) Level() LogLevel

Level retrieve the current log level for this logger

func (LevelLogger) Logf

func (l LevelLogger) Logf(msg string, args ...interface{})

Logf logs the provided message

func (LevelLogger) Tracef

func (l LevelLogger) Tracef(msg string, args ...interface{})

Tracef used to log trace related messages

func (LevelLogger) Warnf

func (l LevelLogger) Warnf(msg string, args ...interface{})

Warnf used to log warning related messages

type LogLevel

type LogLevel int

LogLevel specifies logging level (i.e. DEBUG, WARN)

const (
	// LogTrace most verbose level
	LogTrace LogLevel = iota
	// LogDebug used when more information than normal is needed
	LogDebug LogLevel = iota
	// LogWarn only logs warnings and errors
	LogWarn LogLevel = iota
)

type LogLevelRetriever

type LogLevelRetriever interface {
	Level() LogLevel
}

LogLevelRetriever retrieves the log level

type Logger

type Logger interface {
	Logf(string, ...interface{})
}

Logger interface that defines the logger functions

type LoggerWithLevels

type LoggerWithLevels interface {
	Errorf(msg string, args ...interface{})
	Warnf(msg string, args ...interface{})
	Debugf(msg string, args ...interface{})
	Tracef(msg string, args ...interface{})
	Logf(msg string, args ...interface{})
}

LoggerWithLevels wraps a ui.UI with logging levels

type NoTTYLogger

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

NoTTYLogger struct that interacts with the UI. This logger allow writing to the UI when the tty is deactivated

func NewLoggerNoTTY

func NewLoggerNoTTY(ui goui.UI) *NoTTYLogger

NewLoggerNoTTY creates a logger that will write even when tty is deactivated

func (*NoTTYLogger) Logf

func (n *NoTTYLogger) Logf(msg string, args ...interface{})

Logf Prints log to UI when tty is deactivated

type NonRetryableError

type NonRetryableError struct {
	Message string
}

func (NonRetryableError) Error

func (n NonRetryableError) Error() string

type NoopLogger

type NoopLogger struct{}

NoopLogger this logger will not print

func NewNoopLogger

func NewNoopLogger() *NoopLogger

NewNoopLogger creates a new noop logger

func (NoopLogger) Logf

func (n NoopLogger) Logf(string, ...interface{})

Logf does nothing

type PrefixedLogger

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

PrefixedLogger Logger that attached a prefix to each line

func NewIndentedLogger

func NewIndentedLogger(logger Logger) *PrefixedLogger

NewIndentedLogger creates a new logger indented by 2 spaces

func NewPrefixedLogger

func NewPrefixedLogger(prefix string, logger Logger) *PrefixedLogger

NewPrefixedLogger constructor for building a UI with a prefix when logging a message

func (PrefixedLogger) Logf

func (p PrefixedLogger) Logf(msg string, args ...interface{})

Logf logs message provided adds the prefix to each new line of the msg parameter

type ProgressBarLogger

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

ProgressBarLogger display progress bar on output

func (*ProgressBarLogger) End

func (l *ProgressBarLogger) End()

End stops the progress bar and writes the final message

func (*ProgressBarLogger) Start

func (l *ProgressBarLogger) Start(ctx context.Context, progressChan <-chan regv1.Update)

Start the display of the Progress Bar

type ProgressBarNoTTYLogger

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

ProgressBarNoTTYLogger does not display the progress bar

func (*ProgressBarNoTTYLogger) End

func (l *ProgressBarNoTTYLogger) End()

End Write the final message

func (*ProgressBarNoTTYLogger) Start

func (l *ProgressBarNoTTYLogger) Start(ctx context.Context, progressChan <-chan regv1.Update)

Start consuming the progress channel but does not display anything

type ProgressLogger

type ProgressLogger interface {
	Start(ctx context.Context, progress <-chan regv1.Update)
	End()
}

ProgressLogger Progress bar

func NewNoopProgressBar

func NewNoopProgressBar() ProgressLogger

NewNoopProgressBar constructs a Noop Progress bar that will not display anything

func NewProgressBar

func NewProgressBar(logger LoggerWithLevels, finalMessage, errorMessagePrefix string) ProgressLogger

NewProgressBar constructor to build a ProgressLogger responsible for printing out a progress bar using updates when writing to a registry via ggcr

type RepoBasedTagGenerator

type RepoBasedTagGenerator struct{}

RepoBasedTagGenerator implements GenerateTag and generates repo-based tag

func (RepoBasedTagGenerator) GenerateTag

func (tagGen RepoBasedTagGenerator) GenerateTag(item imagedigest.DigestWrap, importRepo regname.Repository) (regname.Tag, error)

GenerateTag generates repo-based tags

type TagGenDigest

type TagGenDigest struct {
	Algorithm string
	Hex       string
}

TagGenDigest contains Algorithm and Hex values of image digest

func (TagGenDigest) Digest

func (t TagGenDigest) Digest() (regv1.Hash, error)

Digest returns regv1.Hash instance

type TagGenerator

type TagGenerator interface {
	GenerateTag(item imagedigest.DigestWrap, destinationRepo regname.Repository) (regname.Tag, error)
}

TagGenerator interface

type Throttle

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

func NewThrottle

func NewThrottle(max int) Throttle

func (Throttle) Done

func (t Throttle) Done()

func (Throttle) Take

func (t Throttle) Take()

type UILogger

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

UILogger struct that interacts with the UI. This logger only writes to the UI when the tty is activated

func NewLogger

func NewLogger(ui goui.UI) *UILogger

NewLogger creates a logger that will write to the ui when tty is activated

func (*UILogger) Logf

func (n *UILogger) Logf(msg string, args ...interface{})

Logf Prints log to UI when tty is activated

type UIPrefixWriter

type UIPrefixWriter struct {
	goui.UI
	// contains filtered or unexported fields
}

UIPrefixWriter prints a prefix when the underlying ui prints a message

func (*UIPrefixWriter) BeginLinef

func (w *UIPrefixWriter) BeginLinef(msg string, args ...interface{})

BeginLinef writes a message and args adding a configured prefix

func (*UIPrefixWriter) Write

func (w *UIPrefixWriter) Write(data []byte) (int, error)

type WithDigest

type WithDigest interface {
	Digest() (regv1.Hash, error)
}

WithDigest are items that Digest() can be called on

Jump to

Keyboard shortcuts

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