filestore

package
v8.3.3+incompatible Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2019 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultObjectStoreTimeout = 4 * time.Hour

DefaultObjectStoreTimeout is the timeout for ObjectStore upload operation

Variables

View Source
var ErrEntityTooLarge = errors.New("Entity is too large")

ErrEntityTooLarge means that the uploaded content is bigger then maximum allowed size

Functions

func BodyUploader

func BodyUploader(rails PreAuthorizer, h http.Handler, p UploadPreparer) http.Handler

BodyUploader is an http.Handler that perform a pre authorization call to rails before hijacking the request body and uploading it. Providing an UploadPreparer allows to customize the upload process

Types

type FileHandler

type FileHandler struct {
	// LocalPath is the path on the disk where file has been stored
	LocalPath string

	// RemoteID is the objectID provided by GitLab Rails
	RemoteID string
	// RemoteURL is ObjectStore URL provided by GitLab Rails
	RemoteURL string

	// Size is the persisted file size
	Size int64

	// Name is the resource name to send back to GitLab rails.
	// It differ from the real file name in order to avoid file collisions
	Name string
	// contains filtered or unexported fields
}

FileHandler represent a file that has been processed for upload it may be either uploaded to an ObjectStore and/or saved on local path.

func SaveFileFromDisk

func SaveFileFromDisk(ctx context.Context, fileName string, opts *SaveFileOpts) (fh *FileHandler, err error)

SaveFileFromDisk open the local file fileName and calls SaveFileFromReader

func SaveFileFromReader

func SaveFileFromReader(ctx context.Context, reader io.Reader, size int64, opts *SaveFileOpts) (fh *FileHandler, err error)

SaveFileFromReader persists the provided reader content to all the location specified in opts. A cleanup will be performed once ctx is Done Make sure the provided context will not expire before finalizing upload with GitLab Rails.

func (*FileHandler) GitLabFinalizeFields

func (fh *FileHandler) GitLabFinalizeFields(prefix string) map[string]string

GitLabFinalizeFields returns a map with all the fields GitLab Rails needs in order to finalize the upload.

func (*FileHandler) MD5

func (fh *FileHandler) MD5() string

MD5 hash of the handled file

func (*FileHandler) SHA256

func (fh *FileHandler) SHA256() string

SHA256 hash of the handled file

type PreAuthorizer

type PreAuthorizer interface {
	PreAuthorizeHandler(next api.HandleFunc, suffix string) http.Handler
}

type SaveFileOpts

type SaveFileOpts struct {
	// TempFilePrefix is the prefix used to create temporary local file
	TempFilePrefix string
	// LocalTempPath is the directory where to write a local copy of the file
	LocalTempPath string
	// RemoteID is the remote ObjectID provided by GitLab
	RemoteID string
	// RemoteURL is the final URL of the file
	RemoteURL string
	// PresignedPut is a presigned S3 PutObject compatible URL
	PresignedPut string
	// PresignedDelete is a presigned S3 DeleteObject compatible URL.
	PresignedDelete string
	// HTTP headers to be sent along with PUT request
	PutHeaders map[string]string

	// Deadline it the S3 operation deadline, the upload will be aborted if not completed in time
	Deadline time.Time

	//MultipartUpload parameters
	// PartSize is the exact size of each uploaded part. Only the last one can be smaller
	PartSize int64
	// PresignedParts contains the presigned URLs for each part
	PresignedParts []string
	// PresignedCompleteMultipart is a presigned URL for CompleteMulipartUpload
	PresignedCompleteMultipart string
	// PresignedAbortMultipart is a presigned URL for AbortMultipartUpload
	PresignedAbortMultipart string
}

SaveFileOpts represents all the options available for saving a file to object store

func GetOpts

func GetOpts(apiResponse *api.Response) *SaveFileOpts

GetOpts converts GitLab api.Response to a proper SaveFileOpts

func (*SaveFileOpts) IsLocal

func (s *SaveFileOpts) IsLocal() bool

IsLocal checks if the options require the writing of the file on disk

func (*SaveFileOpts) IsMultipart

func (s *SaveFileOpts) IsMultipart() bool

IsMultipart checks if the options requires a Multipart upload

func (*SaveFileOpts) IsRemote

func (s *SaveFileOpts) IsRemote() bool

IsRemote checks if the options requires a remote upload

type SizeError

type SizeError error

type UploadPreparer

type UploadPreparer interface {
	// Prepare converts api.Response into a *SaveFileOpts, it can optionally return an UploadVerifier that will be
	// invoked after the real upload, before the finalization with rails
	Prepare(a *api.Response) (*SaveFileOpts, UploadVerifier, error)
}

UploadPreparer allows to customize BodyUploader configuration

type UploadVerifier

type UploadVerifier interface {
	// Verify can abort the upload returning an error
	Verify(handler *FileHandler) error
}

UploadVerifier allows to check an upload before sending it to rails

Jump to

Keyboard shortcuts

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