helpers

package
v0.102.1 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package helpers provides useful wrappers for clients using the lakeFS OpenAPI.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnsupportedProtocol is the error returned when lakeFS server requests the client
	// use a protocol it does not know about.  Until recompiled to use a newer client,
	// upload the object using through the lakeFS server.
	ErrUnsupportedProtocol = errors.New("unsupported protocol")

	// ErrRequestFailed is an error returned for failing lakeFS server replies.
	ErrRequestFailed = errors.New("request failed")
	ErrConflict      = errors.New("conflict")
)

Functions

func ClientDownload

func ClientDownload(ctx context.Context, client api.ClientWithResponsesInterface, repoID, ref, filePath string) (*api.ObjectStats, io.ReadCloser, error)

ClientDownload downloads a file using client-side ("direct") access to underlying storage. It requires credentials both to lakeFS and to underlying storage, but considerably reduces the load on the lakeFS server.

func ClientUploadDirect added in v0.91.0

func ClientUploadDirect(ctx context.Context, client api.ClientWithResponsesInterface, repoID, branchID, objPath string, metadata map[string]string, contentType string, contents io.ReadSeeker) (*api.ObjectStats, error)

ClientUploadDirect uploads contents as a file using client-side ("direct") access to underlying storage. It requires credentials both to lakeFS and to underlying storage, but considerably reduces the load on the lakeFS server.

func ClientUploadPreSign added in v0.91.0

func ClientUploadPreSign(ctx context.Context, client api.ClientWithResponsesInterface, repoID, branchID, objPath string, metadata map[string]string, contentType string, contents io.ReadSeeker) (*api.ObjectStats, error)

func HTTPResponseAsError added in v0.58.0

func HTTPResponseAsError(httpResponse *http.Response) error

func ResponseAsError

func ResponseAsError(response interface{}) error

ResponseAsError returns a UserVisibleAPIError wrapping an ErrRequestFailed wrapping a response from the server. It searches for a non-nil unsuccessful HTTPResponse field and uses its message, along with a Body that it assumes is an api.Error.

Types

type APIFields added in v0.53.1

type APIFields struct {
	StatusCode int
	Status     string
	Message    string
}

APIFields are fields to use to format an HTTP error response that can be shown to the user.

type AdapterFactory

type AdapterFactory map[string]func() (ClientAdapter, error)

type CallFailedError added in v0.53.1

type CallFailedError struct {
	Err     error
	Message string
}

CallFailedError is an error performing the HTTP request itself formatted to be shown to a user. It does _not_ update its message when wrapped so usually should not be wrapped.

func (CallFailedError) Error added in v0.53.1

func (e CallFailedError) Error() string

func (CallFailedError) Unwrap added in v0.53.1

func (e CallFailedError) Unwrap() error

type ClientAdapter

type ClientAdapter interface {
	// Upload uploads data from contents to physicalAddress and returns stored stats.
	// Returned MTime may be zero.
	Upload(ctx context.Context, physicalAddress *url.URL, contents io.ReadSeeker) (ObjectStats, error)

	// Download returns a Reader to download data from physicalAddress.  The Close method
	// of that Reader can return errors!
	Download(ctx context.Context, physicalAddress *url.URL) (io.ReadCloser, error)
}

ClientAdapter abstracts operations on a backing store.

func NewAdapter

func NewAdapter(protocol string) (ClientAdapter, error)

NewAdapter returns a ClientAdapter for protocol.

type ObjectStats

type ObjectStats struct {
	// Size is the number of bytes.
	Size int64
	// ETag is a unique identifier of the contents.
	ETag string
	// MTime is the time stored for last object modification.  It can be returned as 0
	// from calls to ClientAdapter.Upload().
	MTime time.Time
}

ObjectStats metadata of an object stored on a backing store.

type UserVisibleAPIError added in v0.53.1

type UserVisibleAPIError struct {
	APIFields
	Err error
}

UserVisibleAPIError is an HTTP error response formatted to be shown to a user. It does _not_ update its message when wrapped so usually should not be wrapped.

func (UserVisibleAPIError) Error added in v0.53.1

func (e UserVisibleAPIError) Error() string

func (UserVisibleAPIError) Unwrap added in v0.53.1

func (e UserVisibleAPIError) Unwrap() error

Jump to

Keyboard shortcuts

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