client

package
v3.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2025 License: MIT Imports: 24 Imported by: 1

Documentation

Overview

Package client contains the REST API client for easy use with interacting with a Telemetry server

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound indicates that a request returned no results.
	ErrNotFound = errors.New("no records found for requested object")
)

Functions

func BottleDetailURL

func BottleDetailURL(u url.URL, dgst digest.Digest) string

BottleDetailURL returns the URL to use to view the bottle with the given bottleDigest in a browser. u is the telemetry server base URL and dgst is the bottle config digest.

func BottleSearch

func BottleSearch(ctx context.Context, c *http.Client, handler http.Handler,
	u *url.URL, selectors []string, description string, limit int, digestOnly bool, options ...AuthRequestOptsFunc,
) ([]types.SearchResult, error)

BottleSearch will make a call to the BottleSearch Handler.

func Download

func Download(ctx context.Context, c *http.Client, since time.Time, fromLatest bool, batchSize int, file string, u *url.URL, token string) error

Download raw objects.

func DownloadAll

func DownloadAll(ctx context.Context, c *http.Client, since time.Time, fromLatest bool, batchSize int, path string, u *url.URL, token string) error

DownloadAll raw files given in the file of all types.

func GetBottlesFromMetric

func GetBottlesFromMetric(ctx context.Context, c *http.Client, handler http.Handler,
	u *url.URL, selector []string, metric string, limit int, desc bool, options ...AuthRequestOptsFunc,
) ([]byte, error)

GetBottlesFromMetric will call the handleGetBottlesFromMetric from api.

func GetLocations

func GetLocations(ctx context.Context, c *http.Client, handler http.Handler,
	u *url.URL,
	dgst digest.Digest, options ...AuthRequestOptsFunc,
) ([]types.LocationResponse, error)

GetLocations returns the location response for the bottle digest passed in.

func NewRequestClientFromConfig

func NewRequestClientFromConfig(conf v1alpha2.ClientConfiguration) (*http.Client, error)

NewRequestClientFromConfig creates a http.Client from the given configuration.

func Upload

func Upload(ctx context.Context, c *http.Client, file string, u *url.URL, token string, skipInvalid bool) error

Upload all raw files given in the file.

func UploadAll

func UploadAll(ctx context.Context, c *http.Client, path string, u *url.URL, token string, skipInvalid bool) error

UploadAll raw files given in the file of all types.

Types

type AuthRequestOptsFunc

type AuthRequestOptsFunc func(*http.Request) error

AuthRequestOptsFunc can be passed to all API requests to customize the API request with auth options.

func WithBearerTokenAuth

func WithBearerTokenAuth(token string) AuthRequestOptsFunc

WithBearerTokenAuth takes a token which is then used when making this one request.

type Client

type Client interface {

	// SendEvent sends an event to the Telemetry server using context, algorithm, eventJSON, manifestJSON, bottleConfigJSON, getArtifactData function
	SendEvent(ctx context.Context, alg digest.Algorithm, eventJSON, manifestJSON, bottleConfigJSON []byte, getArtifactData GetArtifactDataFunc) error
	// SendManifest sends a manifest to the Telemetry server using context, algorithm, manifestJSON, bottleConfigJSON, getArtifactData function
	SendManifest(ctx context.Context, alg digest.Algorithm, manifestJSON, bottleConfigJSON []byte, getArtifactData GetArtifactDataFunc) error
	// SendBottle sends a bottle JSON to the Telemetry Server using context, algorithm, bottleConfigJSON, getArtifactData function
	SendBottle(ctx context.Context, alg digest.Algorithm, bottleConfigJSON []byte, getArtifactData GetArtifactDataFunc) error
	// SendSignature sends a signature JSON to the Telemetry Server using context, algorithm, signatureJSON, getArtifactData function
	SendSignature(ctx context.Context, alg digest.Algorithm, signatureJSON []byte, getArtifactData GetArtifactDataFunc) error
	// PutEvent makes a PUT request to the Telemetry Server on an Event using algorithm and eventJSON
	PutEvent(ctx context.Context, alg digest.Algorithm, eventJSON []byte) error
	// PutManifest makes a PUT request to the Telemetry Server on a Manifest using algorithm and manifestJSON
	PutManifest(ctx context.Context, alg digest.Algorithm, manifestJSON []byte) error
	// PutBottle makes a PUT request to the Telemetry Server on a Bottle using algorithm and bottleConfigJSON
	PutBottle(ctx context.Context, alg digest.Algorithm, bottleConfigJSON []byte) error
	// PutSignature makes a PUT request to the Telemetry Server on a Signature using algorithm and signatureJSON
	PutSignature(ctx context.Context, alg digest.Algorithm, signatureJSON []byte) error
	// PutBlob makes a PUT request to the Telemetry Server on a Blob using algorithm and blob of JSON type
	PutBlob(ctx context.Context, alg digest.Algorithm, blob []byte) error

	// ListBlobs returns Blobs Lists details of type ListResultEntry and an error based of specified time and limit, on successful GET request to the telemetry Server
	ListBlobs(ctx context.Context, since time.Time, limit int) ([]types.ListResultEntry, error)
	// ListBottles returns Bottles Lists details of type ListResultEntry and an error based of specified time and limit, on successful GET request to the telemetry Server
	ListBottles(ctx context.Context, since time.Time, limit int) ([]types.ListResultEntry, error)
	// ListManifests returns Manifests Lists details of type ListResultEntry and an error based of specified time and limit, on successful GET request to the telemetry Server
	ListManifests(ctx context.Context, since time.Time, limit int) ([]types.ListResultEntry, error)
	// ListEvents returns Events Lists details of type ListResultEntry and an error based of specified time and limit, on successful GET request to the telemetry Server
	ListEvents(ctx context.Context, since time.Time, limit int) ([]types.ListResultEntry, error)

	// GetBlob retrieves and returns a blob with its digest
	GetBlob(ctx context.Context, dgst digest.Digest) ([]byte, error)
	// GetBottle retrieves and returns a bottle with its digest
	GetBottle(ctx context.Context, dgst digest.Digest) ([]byte, error)
	// GetManifest retrieves and returns a Manifest with its digest
	GetManifest(ctx context.Context, dgst digest.Digest) ([]byte, error)
	// GetEvent retrieves and returns an Event with its digest
	GetEvent(ctx context.Context, dgst digest.Digest) ([]byte, error)

	// Upload will upload a file to server
	Upload(ctx context.Context, file string, skipInvalid bool) error
	// UploadAll will upload files in the directory given
	UploadAll(ctx context.Context, directory string, skipInvalid bool) error

	// Download will download a specified file from specified time parameter
	Download(ctx context.Context, since time.Time, fromlatest bool, batchSize int, file string) error
	// DownloadAll will download all files in specified path from specified time parameter
	DownloadAll(ctx context.Context, since time.Time, fromlatest bool, batchSize int, directory string) error

	// GetLocations will use a bottle digest to return and retrieve the location of type LocationResponse for a bottle
	GetLocations(ctx context.Context, bottledigest digest.Digest) ([]types.LocationResponse, error)
	// BottleSearch will search for a Bottle with selectors, description and return result in SearchResult type format
	BottleSearch(ctx context.Context, selectors []string, description string, limit int, digestOnly bool) ([]types.SearchResult, error)
	// GetBottlesFromMetric will retrieve and return bottles with selectors and metric metric in a slice
	GetBottlesFromMetric(ctx context.Context, selectors []string, metric string, limit int, desc bool) ([]byte, error)
}

Client Interface defines an interface for interracting with a telemetry server.

type Dummy

type Dummy struct{}

Dummy will be used for logging.

func (*Dummy) BottleSearch

func (dc *Dummy) BottleSearch(ctx context.Context, selectors []string, description string, limit int, digestOnly bool) ([]types.SearchResult, error)

BottleSearch will make a Dummy BottleSearch call.

func (*Dummy) Download

func (dc *Dummy) Download(ctx context.Context, since time.Time, fromlatest bool, batchSize int, file string) error

Download will make a Dummy Download call.

func (*Dummy) DownloadAll

func (dc *Dummy) DownloadAll(ctx context.Context, since time.Time, fromlatest bool, batchSize int, path string) error

DownloadAll will make a Dummy DownloadAll call.

func (*Dummy) GetBlob

func (dc *Dummy) GetBlob(ctx context.Context, dgst digest.Digest) ([]byte, error)

GetBlob will make a Dummy GetBlob call.

func (*Dummy) GetBottle

func (dc *Dummy) GetBottle(ctx context.Context, dgst digest.Digest) ([]byte, error)

GetBottle will make a Dummy GetBottle call.

func (*Dummy) GetBottlesFromMetric

func (dc *Dummy) GetBottlesFromMetric(ctx context.Context, selectors []string, metric string, limit int, desc bool) ([]byte, error)

GetBottlesFromMetric will make a Dummy GetBottlesFromMetric call.

func (*Dummy) GetEvent

func (dc *Dummy) GetEvent(ctx context.Context, dgst digest.Digest) ([]byte, error)

GetEvent will make a Dummy GetEvent call.

func (*Dummy) GetLocations

func (dc *Dummy) GetLocations(ctx context.Context, bottledigest digest.Digest) ([]types.LocationResponse, error)

GetLocations will make a Dummy GetLocations call.

func (*Dummy) GetManifest

func (dc *Dummy) GetManifest(ctx context.Context, dgst digest.Digest) ([]byte, error)

GetManifest will make a Dummy GetManifest call.

func (*Dummy) ListBlobs

func (dc *Dummy) ListBlobs(ctx context.Context, since time.Time, limit int) ([]types.ListResultEntry, error)

ListBlobs will make a Dummy ListBlobs call.

func (*Dummy) ListBottles

func (dc *Dummy) ListBottles(ctx context.Context, since time.Time, limit int) ([]types.ListResultEntry, error)

ListBottles will make a Dummy ListBottles call.

func (*Dummy) ListEvents

func (dc *Dummy) ListEvents(ctx context.Context, since time.Time, limit int) ([]types.ListResultEntry, error)

ListEvents will make a Dummy ListEvents call.

func (*Dummy) ListManifests

func (dc *Dummy) ListManifests(ctx context.Context, since time.Time, limit int) ([]types.ListResultEntry, error)

ListManifests will make a Dummy ListManifests call.

func (*Dummy) PutBlob

func (dc *Dummy) PutBlob(ctx context.Context, alg digest.Algorithm, blob []byte) error

PutBlob will make a Dummy PutBlob call.

func (*Dummy) PutBottle

func (dc *Dummy) PutBottle(ctx context.Context, alg digest.Algorithm, bottleConfigJSON []byte) error

PutBottle will make a Dummy PutBottle call.

func (*Dummy) PutEvent

func (dc *Dummy) PutEvent(ctx context.Context, alg digest.Algorithm, eventJSON []byte) error

PutEvent will make a Dummy PutEvent call.

func (*Dummy) PutManifest

func (dc *Dummy) PutManifest(ctx context.Context, alg digest.Algorithm, manifestJSON []byte) error

PutManifest will make a Dummy PutManifest call.

func (*Dummy) PutSignature

func (dc *Dummy) PutSignature(ctx context.Context, alg digest.Algorithm, signatureJSON []byte) error

PutSignature will make a Dummy PutBottle call.

func (*Dummy) SendBottle

func (dc *Dummy) SendBottle(ctx context.Context, alg digest.Algorithm, bottleConfigJSON []byte, getArtifactData GetArtifactDataFunc) error

SendBottle will make a Dummy SendBottle call.

func (*Dummy) SendEvent

func (dc *Dummy) SendEvent(ctx context.Context, alg digest.Algorithm, eventJSON, manifestJSON, bottleConfigJSON []byte, getArtifactData GetArtifactDataFunc) error

SendEvent will make a Dummy sendevent call.

func (*Dummy) SendManifest

func (dc *Dummy) SendManifest(ctx context.Context, alg digest.Algorithm, manifestJSON, bottleConfigJSON []byte, getArtifactData GetArtifactDataFunc) error

SendManifest will make a Dummy SendManifest call.

func (*Dummy) SendSignature

func (dc *Dummy) SendSignature(ctx context.Context, alg digest.Algorithm, signatureJSON []byte, getArtifactData GetArtifactDataFunc) error

SendSignature will make a Dummy SendBottle call.

func (*Dummy) Upload

func (dc *Dummy) Upload(ctx context.Context, file string, skipInvalid bool) error

Upload will make a Dummy Upload call.

func (*Dummy) UploadAll

func (dc *Dummy) UploadAll(ctx context.Context, path string, skipInvalid bool) error

UploadAll will make a Dummy UploadAll call.

type GetArtifactDataFunc

type GetArtifactDataFunc func(dgst digest.Digest) ([]byte, error)

GetArtifactDataFunc returns the data for an artifact with the given digest.

type MultiClient

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

MultiClient has an array of Client Interfaces.

func NewMultiClient

func NewMultiClient(clients []Client) *MultiClient

NewMultiClient creates a MultiClient from an array of Clients.

func (*MultiClient) BottleSearch

func (mc *MultiClient) BottleSearch(ctx context.Context, selectors []string, description string, limit int, digestOnly bool) ([]types.SearchResult, error)

BottleSearch will return the Location Response.

func (*MultiClient) Download

func (mc *MultiClient) Download(ctx context.Context, since time.Time, fromlatest bool, batchSize int, file string) error

Download will use our client to call Download function.

func (*MultiClient) DownloadAll

func (mc *MultiClient) DownloadAll(ctx context.Context, since time.Time, fromlatest bool, batchSize int, path string) error

DownloadAll will use our client to call DownloadAll request function.

func (*MultiClient) GetBlob

func (mc *MultiClient) GetBlob(ctx context.Context, dgst digest.Digest) ([]byte, error)

GetBlob will get blob against each client.

func (*MultiClient) GetBottle

func (mc *MultiClient) GetBottle(ctx context.Context, dgst digest.Digest) ([]byte, error)

GetBottle will make a get bottle request to the api with the digest.

func (*MultiClient) GetBottlesFromMetric

func (mc *MultiClient) GetBottlesFromMetric(ctx context.Context, selectors []string, metric string, limit int, desc bool) ([]byte, error)

GetBottlesFromMetric will return the bottles using metric.

func (*MultiClient) GetEvent

func (mc *MultiClient) GetEvent(ctx context.Context, dgst digest.Digest) ([]byte, error)

GetEvent will make a get event request to the api with the digest.

func (*MultiClient) GetLocations

func (mc *MultiClient) GetLocations(ctx context.Context, bottledigest digest.Digest) ([]types.LocationResponse, error)

GetLocations will return the Location Response.

func (*MultiClient) GetManifest

func (mc *MultiClient) GetManifest(ctx context.Context, dgst digest.Digest) ([]byte, error)

GetManifest will make a get manifest request to the api with the digest.

func (*MultiClient) ListBlobs

func (mc *MultiClient) ListBlobs(ctx context.Context, since time.Time, limit int) ([]types.ListResultEntry, error)

ListBlobs will make a get a list of blobs from a specific time.

func (*MultiClient) ListBottles

func (mc *MultiClient) ListBottles(ctx context.Context, since time.Time, limit int) ([]types.ListResultEntry, error)

ListBottles will make a get a bottles list from a specific time.

func (*MultiClient) ListEvents

func (mc *MultiClient) ListEvents(ctx context.Context, since time.Time, limit int) ([]types.ListResultEntry, error)

ListEvents will make a get an events list from a specific time.

func (*MultiClient) ListManifests

func (mc *MultiClient) ListManifests(ctx context.Context, since time.Time, limit int) ([]types.ListResultEntry, error)

ListManifests will make a get a manifests list from a specific time.

func (*MultiClient) PutBlob

func (mc *MultiClient) PutBlob(ctx context.Context, alg digest.Algorithm, blob []byte) error

PutBlob will make a put blob request to the api.

func (*MultiClient) PutBottle

func (mc *MultiClient) PutBottle(ctx context.Context, alg digest.Algorithm, bottleConfigJSON []byte) error

PutBottle will make a put bottle request to the api.

func (*MultiClient) PutEvent

func (mc *MultiClient) PutEvent(ctx context.Context, alg digest.Algorithm, eventJSON []byte) error

PutEvent will make a put event request to the api.

func (*MultiClient) PutManifest

func (mc *MultiClient) PutManifest(ctx context.Context, alg digest.Algorithm, manifestJSON []byte) error

PutManifest will make a put manifest request to the api.

func (*MultiClient) PutSignature

func (mc *MultiClient) PutSignature(ctx context.Context, alg digest.Algorithm, signatureJSON []byte) error

PutSignature will make a put signature request to the api.

func (*MultiClient) SendBottle

func (mc *MultiClient) SendBottle(ctx context.Context, alg digest.Algorithm, bottleConfigJSON []byte, getArtifactData GetArtifactDataFunc) error

SendBottle will send a bottle JSON to the api.

func (*MultiClient) SendEvent

func (mc *MultiClient) SendEvent(ctx context.Context, alg digest.Algorithm, eventJSON, manifestJSON, bottleConfigJSON []byte, getArtifactData GetArtifactDataFunc) error

SendEvent will send an event to the api using the MultiClient.

func (*MultiClient) SendManifest

func (mc *MultiClient) SendManifest(ctx context.Context, alg digest.Algorithm, manifestJSON, bottleConfigJSON []byte, getArtifactData GetArtifactDataFunc) error

SendManifest will send a manifest JSON to the api.

func (*MultiClient) SendSignature

func (mc *MultiClient) SendSignature(ctx context.Context, alg digest.Algorithm, signatureJSON []byte, getArtifactData GetArtifactDataFunc) error

SendSignature will send an event to the api using the MultiClient.

func (*MultiClient) Upload

func (mc *MultiClient) Upload(ctx context.Context, file string, skipInvalid bool) error

Upload will upload files to api.

func (*MultiClient) UploadAll

func (mc *MultiClient) UploadAll(ctx context.Context, path string, skipInvalid bool) error

UploadAll will call UploadAll function from requests.

type Single

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

Single will represent our client to make http requests.

func NewSingleClient

func NewSingleClient(httpClient *http.Client, serverURL string, token string) (*Single, error)

NewSingleClient creates a new client to connect to the given telemetry server.

func (*Single) BottleSearch

func (sc *Single) BottleSearch(ctx context.Context, selectors []string, description string, limit int, digestOnly bool) ([]types.SearchResult, error)

BottleSearch will return the Location Response.

func (*Single) Download

func (sc *Single) Download(ctx context.Context, since time.Time, fromlatest bool, batchSize int, file string) error

Download will use our client to call Download function.

func (*Single) DownloadAll

func (sc *Single) DownloadAll(ctx context.Context, since time.Time, fromlatest bool, batchSize int, path string) error

DownloadAll will use our client to call DownloadAll request function.

func (*Single) GetBlob

func (sc *Single) GetBlob(ctx context.Context, dgst digest.Digest) ([]byte, error)

GetBlob will make a get blob request to the api with the digest.

func (*Single) GetBottle

func (sc *Single) GetBottle(ctx context.Context, dgst digest.Digest) ([]byte, error)

GetBottle will make a get bottle request to the api with the digest.

func (*Single) GetBottlesFromMetric

func (sc *Single) GetBottlesFromMetric(ctx context.Context, selectors []string, metric string, limit int, desc bool) ([]byte, error)

GetBottlesFromMetric will return the bottles using metric.

func (*Single) GetEvent

func (sc *Single) GetEvent(ctx context.Context, dgst digest.Digest) ([]byte, error)

GetEvent will make a get event request to the api with the digest.

func (*Single) GetLocations

func (sc *Single) GetLocations(ctx context.Context, bottledigest digest.Digest) ([]types.LocationResponse, error)

GetLocations will return the Location Response.

func (*Single) GetManifest

func (sc *Single) GetManifest(ctx context.Context, dgst digest.Digest) ([]byte, error)

GetManifest will make a get manifest request to the api with the digest.

func (*Single) ListBlobs

func (sc *Single) ListBlobs(ctx context.Context, since time.Time, limit int) ([]types.ListResultEntry, error)

ListBlobs will make a get a blobs list using since.

func (*Single) ListBottles

func (sc *Single) ListBottles(ctx context.Context, since time.Time, limit int) ([]types.ListResultEntry, error)

ListBottles will make a get a bottles list using since.

func (*Single) ListEvents

func (sc *Single) ListEvents(ctx context.Context, since time.Time, limit int) ([]types.ListResultEntry, error)

ListEvents will make a get an events list using since.

func (*Single) ListManifests

func (sc *Single) ListManifests(ctx context.Context, since time.Time, limit int) ([]types.ListResultEntry, error)

ListManifests will make a get a manifests list using since.

func (*Single) PutBlob

func (sc *Single) PutBlob(ctx context.Context, alg digest.Algorithm, blob []byte) error

PutBlob will make a put blob request to the api.

func (*Single) PutBottle

func (sc *Single) PutBottle(ctx context.Context, alg digest.Algorithm, bottleConfigJSON []byte) error

PutBottle will make a put bottle request to the api.

func (*Single) PutEvent

func (sc *Single) PutEvent(ctx context.Context, alg digest.Algorithm, eventJSON []byte) error

PutEvent will make a put event request to the api.

func (*Single) PutManifest

func (sc *Single) PutManifest(ctx context.Context, alg digest.Algorithm, manifestJSON []byte) error

PutManifest will make a put manifest request to the api.

func (*Single) PutSignature

func (sc *Single) PutSignature(ctx context.Context, alg digest.Algorithm, signatureJSON []byte) error

PutSignature will make a put event request to the api.

func (*Single) SendBottle

func (sc *Single) SendBottle(ctx context.Context, alg digest.Algorithm, bottleConfigJSON []byte, getArtifactData GetArtifactDataFunc) error

SendBottle will send a bottle JSON to the api.

func (*Single) SendEvent

func (sc *Single) SendEvent(ctx context.Context, alg digest.Algorithm, eventJSON, manifestJSON, bottleConfigJSON []byte, getArtifactData GetArtifactDataFunc) error

SendEvent will send an event JSON to the api.

func (*Single) SendManifest

func (sc *Single) SendManifest(ctx context.Context, alg digest.Algorithm, manifestJSON, bottleConfigJSON []byte, getArtifactData GetArtifactDataFunc) error

SendManifest will send a manifest JSON to the api.

func (*Single) SendSignature

func (sc *Single) SendSignature(ctx context.Context, alg digest.Algorithm, signatureJSON []byte, getArtifactData GetArtifactDataFunc) error

SendSignature will send an event JSON to the api.

func (*Single) Upload

func (sc *Single) Upload(ctx context.Context, file string, skipInvalid bool) error

Upload will upload files to api.

func (*Single) UploadAll

func (sc *Single) UploadAll(ctx context.Context, path string, skipInvalid bool) error

UploadAll will call UploadAll function from requests.

Jump to

Keyboard shortcuts

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