lib

package
v0.0.0-...-969384c Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// RepositorySubexp is the name for sub regex that maps to repository name in the url
	RepositorySubexp = "repository"
	// ReferenceSubexp is the name for sub regex that maps to reference (tag or digest) url
	ReferenceSubexp = "reference"
	// DigestSubexp is the name for sub regex that maps to digest in the url
	DigestSubexp = "digest"
)
View Source
const KBRATE = 1024 / 8

Variables

View Source
var (
	// V2ManifestURLRe is the regular expression for matching request v2 handler to view/delete manifest
	V2ManifestURLRe = regexp.MustCompile(fmt.Sprintf(`^/v2/(?P<%s>%s)/manifests/(?P<%s>.*)$`, RepositorySubexp, reference.NameRegexp.String(), ReferenceSubexp))
	// V2TagListURLRe is the regular expression for matching request to v2 handler to list tags
	V2TagListURLRe = regexp.MustCompile(fmt.Sprintf(`^/v2/(?P<%s>%s)/tags/list`, RepositorySubexp, reference.NameRegexp.String()))
	// V2BlobURLRe is the regular expression for matching request to v2 handler to retrieve head/delete a blob
	V2BlobURLRe = regexp.MustCompile(fmt.Sprintf(`^/v2/(?P<%s>%s)/blobs/(?P<%s>%s)$`, RepositorySubexp, reference.NameRegexp.String(), DigestSubexp, digest.DigestRegexp.String()))
	// V2BlobUploadURLRe is the regular expression for matching the request to v2 handler to upload a blob, the upload uuid currently is not put into a group
	V2BlobUploadURLRe = regexp.MustCompile(fmt.Sprintf(`^/v2/(?P<%s>%s)/blobs/uploads[/a-zA-Z0-9\-_\.=]*$`, RepositorySubexp, reference.NameRegexp.String()))
	// V2CatalogURLRe is the regular expression for matching the request to v2 handler to list catalog
	V2CatalogURLRe = regexp.MustCompile(`^/v2/_catalog(/.*)?$`)
	// V2ReferrersURLRe is the regular expression for matching request to v2 handler to list referrers
	V2ReferrersURLRe = regexp.MustCompile(fmt.Sprintf(`^/v2/(?P<%s>%s)/referrers/(?P<%s>.*)$`, RepositorySubexp, reference.NameRegexp.String(), ReferenceSubexp))
	// RepositoryNameRe is the regular expression for  matching repository name
	RepositoryNameRe = regexp.MustCompile(fmt.Sprintf("^%s$", reference.NameRegexp))
)

Functions

func BoolValue

func BoolValue(v *bool) bool

BoolValue returns the value of the bool pointer or false if the pointer is nil

func GetAPIVersion

func GetAPIVersion(ctx context.Context) string

GetAPIVersion gets the API version from the context

func GetAuthMode

func GetAuthMode(ctx context.Context) string

GetAuthMode gets the auth mode from the context

func GetCarrySession

func GetCarrySession(ctx context.Context) bool

GetCarrySession gets the "carry session" from the context indicates whether the request carries session or not

func GetXRequestID

func GetXRequestID(ctx context.Context) string

GetXRequestID gets the XRequestID from the context

func Int64Value

func Int64Value(v *int64) int64

Int64Value returns the value of the int64 pointer or 0 if the pointer is nil

func JSONCopy

func JSONCopy(dst, src interface{}) error

JSONCopy copy from src to dst with json marshal and unmarshal. NOTE: copy from one struct to another struct may miss some values depend on the json tag in the fields, you should know what will happened when call this function.

func MatchBlobURLPattern

func MatchBlobURLPattern(path string) (repository, digest string, match bool)

MatchBlobURLPattern checks whether the provided path matches the blob URL pattern, if does, returns the repository and reference as well

func MatchBlobUploadURLPattern

func MatchBlobUploadURLPattern(path string) (repository string, match bool)

MatchBlobUploadURLPattern checks whether the provided path matches the blob upload URL pattern, if does, returns the repository as well

func MatchManifestURLPattern

func MatchManifestURLPattern(path string) (repository, reference string, match bool)

MatchManifestURLPattern checks whether the provided path matches the manifest URL pattern, if does, returns the repository and reference as well

func NewReader

func NewReader(r io.ReadCloser, kb int32) io.ReadCloser

NewReader returns a Reader that is rate limited

func NopCloseRequest

func NopCloseRequest(r *http.Request) *http.Request

NopCloseRequest ...

func ShuffleStringSlice

func ShuffleStringSlice(slice []string)

ShuffleStringSlice shuffles the string slice in place.

func StringValue

func StringValue(v *string) string

StringValue returns the value of the string pointer or "" if the pointer is nil

func Title

func Title(s string) string

Title uppercase the first character, and lower case the rest, for example covert MANUAL to Manual

func ToBool

func ToBool(v interface{}) bool

ToBool convert interface to bool

func TrimLineBreaks

func TrimLineBreaks(s string) string

TrimLineBreaks trims line breaks in string.

func Truncate

func Truncate(str, suffix string, n int) string

Truncate tries to append the "suffix" to the "str". If the length of the appended string exceeds "n", the function truncates the "str" to make sure the "suffix" is appended

func ValidateHTTPURL

func ValidateHTTPURL(s string) (string, error)

ValidateHTTPURL checks whether the provided string is a valid HTTP URL. If it is, return the URL in format "scheme://host:port" to avoid the SSRF

func ValidateQuotaLimit

func ValidateQuotaLimit(storageLimit int64) error

func WithAPIVersion

func WithAPIVersion(ctx context.Context, version string) context.Context

WithAPIVersion returns a context with APIVersion set

func WithArtifactInfo

func WithArtifactInfo(ctx context.Context, art ArtifactInfo) context.Context

WithArtifactInfo returns a context with ArtifactInfo set

func WithAuthMode

func WithAuthMode(ctx context.Context, mode string) context.Context

WithAuthMode returns a context with auth mode set

func WithCarrySession

func WithCarrySession(ctx context.Context, carrySession bool) context.Context

WithCarrySession returns a context with "carry session" set that indicates whether the request carries session or not

func WithXRequestID

func WithXRequestID(ctx context.Context, version string) context.Context

WithXRequestID returns a context with XRequestID set

Types

type ArtifactInfo

type ArtifactInfo struct {
	Repository           string
	Reference            string
	ProjectName          string
	Digest               string
	Tag                  string
	BlobMountRepository  string
	BlobMountProjectName string
	BlobMountDigest      string
}

ArtifactInfo wraps the artifact info extracted from the request to "/v2/"

func GetArtifactInfo

func GetArtifactInfo(ctx context.Context) (art ArtifactInfo)

GetArtifactInfo gets the ArtifactInfo from the context

type Authorizer

type Authorizer modifier.Modifier

Authorizer authorizes the request

type Link struct {
	URL   string
	Rel   string
	Attrs map[string]string
}

Link defines the model that describes the HTTP link header

func (*Link) String

func (l *Link) String() string

String returns the string representation of a link

type Links []*Link

Links is a link object array

func ParseLinks(str string) Links

ParseLinks parses the link header into Links e.g. <http://example.com/TheBook/chapter2>; rel="previous"; title="previous chapter" , <http://example.com/TheBook/chapter4>; rel="next"; title="next chapter"

func (Links) String

func (l Links) String() string

String returns the string representation of links

type RateOpts

type RateOpts struct {
	Rate float64
}

type ResponseBuffer

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

ResponseBuffer is a wrapper for the http.ResponseWriter to buffer the response data

func NewResponseBuffer

func NewResponseBuffer(w http.ResponseWriter) *ResponseBuffer

NewResponseBuffer creates a ResponseBuffer object

func (*ResponseBuffer) Buffer

func (r *ResponseBuffer) Buffer() []byte

Buffer returns the buffer of ResponseBuffer

func (*ResponseBuffer) Flush

func (r *ResponseBuffer) Flush() (int, error)

Flush the status code, header and data into the underlying response writer

func (*ResponseBuffer) Header

func (r *ResponseBuffer) Header() http.Header

Header returns the header of the buffer

func (*ResponseBuffer) Reset

func (r *ResponseBuffer) Reset() error

Reset reset the response buffer

func (*ResponseBuffer) StatusCode

func (r *ResponseBuffer) StatusCode() int

StatusCode returns the status code

func (*ResponseBuffer) Success

func (r *ResponseBuffer) Success() bool

Success checks whether the status code is >= 200 & <= 399

func (*ResponseBuffer) Write

func (r *ResponseBuffer) Write(data []byte) (int, error)

Write writes the data into the buffer without writing to the underlying response writer

func (*ResponseBuffer) WriteHeader

func (r *ResponseBuffer) WriteHeader(statusCode int)

WriteHeader writes the status code into the buffer without writing to the underlying response writer

type ResponseRecorder

type ResponseRecorder struct {
	StatusCode int

	http.ResponseWriter
	// contains filtered or unexported fields
}

ResponseRecorder is a wrapper for the http.ResponseWriter to record the response status code

func NewResponseRecorder

func NewResponseRecorder(w http.ResponseWriter) *ResponseRecorder

NewResponseRecorder creates a response recorder

func (*ResponseRecorder) Success

func (r *ResponseRecorder) Success() bool

Success checks whether the status code is >= 200 & <= 399

func (*ResponseRecorder) Write

func (r *ResponseRecorder) Write(data []byte) (int, error)

Write records the status code before writing data to the underlying writer

func (*ResponseRecorder) WriteHeader

func (r *ResponseRecorder) WriteHeader(statusCode int)

WriteHeader records the status code before writing the code to the underlying writer

type Set

type Set map[interface{}]void

Set a simple set

func (Set) Add

func (s Set) Add(item interface{})

Add add item to set

func (Set) Exists

func (s Set) Exists(item interface{}) bool

Exists returns true when item in the set

func (Set) Items

func (s Set) Items() []interface{}

Items returns the items in the set

type WorkerPool

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

WorkerPool controls the concurrency limit of task/process

func NewWorkerPool

func NewWorkerPool(size int32) *WorkerPool

NewWorkerPool creates a new worker pool with specified size

func (*WorkerPool) GetWorker

func (w *WorkerPool) GetWorker()

GetWorker hangs until a free worker available

func (*WorkerPool) ReleaseWorker

func (w *WorkerPool) ReleaseWorker()

ReleaseWorker hangs until the worker return back into the pool

Directories

Path Synopsis
metadata
Package metadata define config related metadata
Package metadata define config related metadata
encode
q

Jump to

Keyboard shortcuts

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