poll

package
v0.0.0-...-ca9423e Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package poll defines an interface for periodically polling repositories for status updates.

Index

Constants

This section is empty.

Variables

Functions

func CleanRepoURL

func CleanRepoURL(url string) string

CleanRepoURL removes protocol and format tags from a repository URL.

func FixRepoURL

func FixRepoURL(s string) string

FixRepoURL ensures s has a valid protocol prefix for Git.

func RepoExists

func RepoExists(ctx context.Context, url string) bool

RepoExists reports whether there is a repository at the specified URL.

A true result means the repository is definitely present, though it may require authentication. A false result may be incorrect, for example if the caller's network filters outbound git requests.

func ShouldCheck

func ShouldCheck(stat *Status, min time.Duration) bool

ShouldCheck reports whether the given status message should be checked, based on its history of previous updates.

No update will be suggested within min of the most recent check. Otherwise, schedule an update once the current time is at least the average gap between updates. // As a special case if min == 0 the answer is always true.

Types

type CheckOptions

type CheckOptions struct {
	// If set, append this label to the repository key.
	Label string

	// If set, use this reference name to resolve a target digest.
	Reference string

	// If set, attribute this prefix to the packages found in the repository.
	Prefix string
}

CheckOptions control optional features of repostory checks. A nil *CheckOptions is ready for use with default values.

type CheckResult

type CheckResult struct {
	URL    string // repository fetch URL
	Name   string // remote head name
	Digest string // current digest value
	Errors int    // errors since last successful update
	Prefix string // package prefix, if defined
	// contains filtered or unexported fields
}

CheckResult records the update status of a repository.

func (*CheckResult) Clone

func (c *CheckResult) Clone(ctx context.Context, path string) error

Clone clones the repository state denoted by c in specified directory path. The directory is created if it does not exist.

func (*CheckResult) NeedsUpdate

func (c *CheckResult) NeedsUpdate() bool

NeedsUpdate reports whether c requires an update.

type DB

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

A DB represents a cache of update statuses for repositories.

func NewDB

func NewDB(st storage.Interface) *DB

NewDB constructs a database handle for the given storage.

func (*DB) Check

func (db *DB) Check(ctx context.Context, url string, opts *CheckOptions) (*CheckResult, error)

Check reports whether the specified repository requires an update. If the repository does not exist, it is added and reported as needing update.

If there is an error in updating the status, the check result will be non-nil and the caller can check the Errors field to see how often an update has been attempted without success. Repositories that fail too often may be pruned from the database.

If url has the form <base>@@<tag>, the specified tag is applied.

func (*DB) Remove

func (db *DB) Remove(ctx context.Context, url, tag string) error

Remove removes the status record for the specified URL.

func (*DB) Scan

func (db *DB) Scan(ctx context.Context, f func(string) error) error

Scan scans all the URLs in the database. If f reports an error, that error is propagated to the caller.

func (*DB) Status

func (db *DB) Status(ctx context.Context, url string) (*Status, error)

Status returns the status record for the specified URL. It is an error if the given URL does not have a record in this database.

func (*DB) Tags

func (db *DB) Tags(ctx context.Context, base string) ([]*Status, error)

Tags returns the status records for all tags of the specified URL.

type Status

type Status struct {
	Repository string `protobuf:"bytes,1,opt,name=repository,proto3" json:"repository,omitempty"`                    // repository fetch URL
	RefName    string `protobuf:"bytes,2,opt,name=ref_name,json=refName,proto3" json:"ref_name,omitempty"`           // reference name to fetch (default is HEAD)
	Digest     []byte `protobuf:"bytes,3,opt,name=digest,proto3" json:"digest,omitempty"`                            // latest known digest
	ErrorCount int32  `protobuf:"varint,6,opt,name=error_count,json=errorCount,proto3" json:"error_count,omitempty"` // fetch errors since last successful check
	Prefix     string `protobuf:"bytes,7,opt,name=prefix,proto3" json:"prefix,omitempty"`                            // package prefix to attribute to this repository
	Tag        string `protobuf:"bytes,8,opt,name=tag,proto3" json:"tag,omitempty"`                                  // storage tag for this status
	// When the last check of this repository was made. If unset, the repository
	// has never been checked.
	LastCheck *timestamppb.Timestamp `protobuf:"bytes,4,opt,name=last_check,json=lastCheck,proto3" json:"last_check,omitempty"`
	// The history of updates, oldest to newest.
	Updates []*Status_Update `protobuf:"bytes,5,rep,name=updates,proto3" json:"updates,omitempty"`
	// contains filtered or unexported fields
}

A Status records the status of a single repository.

func (*Status) Descriptor deprecated

func (*Status) Descriptor() ([]byte, []int)

Deprecated: Use Status.ProtoReflect.Descriptor instead.

func (*Status) GetDigest

func (x *Status) GetDigest() []byte

func (*Status) GetErrorCount

func (x *Status) GetErrorCount() int32

func (*Status) GetLastCheck

func (x *Status) GetLastCheck() *timestamppb.Timestamp

func (*Status) GetPrefix

func (x *Status) GetPrefix() string

func (*Status) GetRefName

func (x *Status) GetRefName() string

func (*Status) GetRepository

func (x *Status) GetRepository() string

func (*Status) GetTag

func (x *Status) GetTag() string

func (*Status) GetUpdates

func (x *Status) GetUpdates() []*Status_Update

func (*Status) MarshalJSON

func (s *Status) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler for a Status by delegating to protojson.

func (*Status) ProtoMessage

func (*Status) ProtoMessage()

func (*Status) ProtoReflect

func (x *Status) ProtoReflect() protoreflect.Message

func (*Status) Reset

func (x *Status) Reset()

func (*Status) String

func (x *Status) String() string

func (*Status) UnmarshalJSON

func (s *Status) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler for a Status by delegating to jsonpb.

type Status_Update

type Status_Update struct {

	// When this update was discovered.
	When *timestamppb.Timestamp `protobuf:"bytes,1,opt,name=when,proto3" json:"when,omitempty"`
	// The digest at the time of this update.
	Digest []byte `protobuf:"bytes,2,opt,name=digest,proto3" json:"digest,omitempty"`
	// contains filtered or unexported fields
}

func (*Status_Update) Descriptor deprecated

func (*Status_Update) Descriptor() ([]byte, []int)

Deprecated: Use Status_Update.ProtoReflect.Descriptor instead.

func (*Status_Update) GetDigest

func (x *Status_Update) GetDigest() []byte

func (*Status_Update) GetWhen

func (x *Status_Update) GetWhen() *timestamppb.Timestamp

func (*Status_Update) ProtoMessage

func (*Status_Update) ProtoMessage()

func (*Status_Update) ProtoReflect

func (x *Status_Update) ProtoReflect() protoreflect.Message

func (*Status_Update) Reset

func (x *Status_Update) Reset()

func (*Status_Update) String

func (x *Status_Update) String() string

Jump to

Keyboard shortcuts

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