yts3

package
v0.0.0-...-86e4c60 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2022 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// From https://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html:
	//	"The name for a key is a sequence of Unicode characters whose UTF-8
	//	encoding is at most 1024 bytes long."
	KeySizeLimit = 1024

	// From https://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html:
	//	Within the PUT request header, the user-defined metadata is limited to 2
	// 	KB in size. The size of user-defined metadata is measured by taking the
	// 	sum of the number of bytes in the UTF-8 encoding of each key and value.
	//
	// As this does not specify KB or KiB, KB is used in gofakes3. The reason
	// for this is if gofakes3 is used for testing, and your tests show that
	// 2KiB works, but Amazon uses 2KB...  that's a much worse time to discover
	// the disparity!
	DefaultMetadataSizeLimit = 2000

	// Like DefaultMetadataSizeLimit, the docs don't specify MB or MiB, so we
	// will accept 5MB for now. The Go client SDK rejects 5MB with the error
	// "part size must be at least 5242880 bytes", which is a hint that it
	// has been interpreted as MiB at least _somewhere_, but we should remain
	// liberal in what we accept in the face of ambiguity.
	DefaultUploadPartSize = 5 * 1000 * 1000

	DefaultSkewLimit = 15 * time.Minute

	MaxUploadsLimit       = 1000
	DefaultMaxUploads     = 1000
	MaxUploadPartsLimit   = 1000
	DefaultMaxUploadParts = 1000

	MaxBucketKeys        = 1000
	DefaultMaxBucketKeys = 1000

	MaxBucketVersionKeys        = 1000
	DefaultMaxBucketVersionKeys = 1000

	// From the docs: "Part numbers can be any number from 1 to 10,000, inclusive."
	MaxUploadPartNumber = 10000
)
View Source
const (
	DefaultBucketVersionKeys = 1000
)
View Source
const RangeNoEnd = -1

Variables

View Source
var GetObjectNum *int32 = new(int32)
View Source
var ListBucketNum *int32 = new(int32)
View Source
var RequestNum *int32 = new(int32)

Functions

func BucketNotFound

func BucketNotFound(bucket string) error

func DirSize

func DirSize(path string) (int64, error)

func ErrorInvalidArgument

func ErrorInvalidArgument(name, value, message string) error

func ErrorMessage

func ErrorMessage(code ErrorCode, message string) error

func ErrorMessagef

func ErrorMessagef(code ErrorCode, message string, args ...interface{}) error

func GetBetweenStr

func GetBetweenStr(str, start, end string) string

func HasErrorCode

func HasErrorCode(err error, code ErrorCode) bool

func IsAlreadyExists

func IsAlreadyExists(err error) bool

func KeyNotFound

func KeyNotFound(key string) error

func ListDir

func ListDir(dirPth string) (files []string, files1 []string, err error)

func ReadAll

func ReadAll(r io.Reader, size int64) (b []byte, err error)

func ResourceError

func ResourceError(code ErrorCode, resource string) error

func Stamp2Str

func Stamp2Str(stamp int64) string

时间戳->字符串

func Stamp2Time

func Stamp2Time(stamp int64) time.Time

时间戳->时间对象

func Str2Stamp

func Str2Stamp(formatTimeStr string) int64

*字符串->时间戳

func Str2Time

func Str2Time(formatTimeStr string) time.Time

*字符串->时间对象

func Time2Stamp

func Time2Stamp() int64

时间对象->时间戳

func Time2Str

func Time2Str() string

*时间对象->字符串

func ValidateBucketName

func ValidateBucketName(name string) error

Types

type Backend

type Backend interface {
	ListBuckets(publicKey string) ([]BucketInfo, error)
	ListBucket(publicKey, name string, prefix *Prefix, page ListBucketPage) (*ObjectList, error)
	CreateBucket(publicKey, name string) error
	DeleteMulti(publicKey, bucketName string, objects ...string) (MultiDeleteResult, error)
	PutObject(publicKey, bucketName, key string, meta map[string]string, input io.Reader, size int64) (PutObjectResult, error)
	MultipartUpload(publicKey, bucketName, objectName string, partsPath []string, size int64) (PutObjectResult, error)
	GetObjectV2(publicKey, bucketName, objectName string, rangeRequest *ObjectRangeRequest, prefix *Prefix, page ListBucketPage) (*Object, error)
	GetObject(publicKey, bucketName, objectName string, rangeRequest *ObjectRangeRequest) (*Object, error)
	DeleteBucket(publicKey, name string) error
	HeadObject(publicKey, bucketName, objectName string) (*Object, error)
	DeleteObject(publicKey, bucketName, objectName string) (ObjectDeleteResult, error)
}

type BucketInfo

type BucketInfo struct {
	Name string `xml:"Name"`

	// CreationDate is required; without it, boto returns the error "('String
	// does not contain a date:', ”)"
	CreationDate ContentTime `xml:"CreationDate"`
}

type Buckets

type Buckets []BucketInfo

type CommonPrefix

type CommonPrefix struct {
	Prefix string `xml:"Prefix"`
}

type CompleteMultipartUploadRequest

type CompleteMultipartUploadRequest struct {
	Parts []CompletedPart `xml:"Part"`
}

type CompleteMultipartUploadResult

type CompleteMultipartUploadResult struct {
	Location string `xml:"Location"`
	Bucket   string `xml:"Bucket"`
	Key      string `xml:"Key"`
	ETag     string `xml:"ETag"`
}

type CompletedPart

type CompletedPart struct {
	PartNumber int    `xml:"PartNumber"`
	ETag       string `xml:"ETag"`
}

type Content

type Content struct {
	Key          string       `xml:"Key"`
	LastModified ContentTime  `xml:"LastModified"`
	ETag         string       `xml:"ETag"`
	Size         int64        `xml:"Size"`
	StorageClass StorageClass `xml:"StorageClass,omitempty"`
	Owner        *UserInfo    `xml:"Owner,omitempty"`
}

type ContentTime

type ContentTime struct {
	time.Time
}

func NewContentTime

func NewContentTime(t time.Time) ContentTime

type CopyObjectResult

type CopyObjectResult struct {
	XMLName      xml.Name    `xml:"CopyObjectResult"`
	ETag         string      `xml:"ETag,omitempty"`
	LastModified ContentTime `xml:"LastModified,omitempty"`
}

type DeleteMarker

type DeleteMarker struct {
	XMLName      xml.Name    `xml:"DeleteMarker"`
	Key          string      `xml:"Key"`
	VersionID    VersionID   `xml:"VersionId"`
	IsLatest     bool        `xml:"IsLatest"`
	LastModified ContentTime `xml:"LastModified,omitempty"`
	Owner        *UserInfo   `xml:"Owner,omitempty"`
}

type DeleteRequest

type DeleteRequest struct {
	Objects []ObjectID `xml:"Object"`

	Quiet bool `xml:"Quiet"`
}

type Error

type Error interface {
	error
	ErrorCode() ErrorCode
}

type ErrorCode

type ErrorCode string
const (
	ErrNone ErrorCode = ""

	ErrBadDigest ErrorCode = "BadDigest"

	ErrInvalidAccessKeyID ErrorCode = "InvalidAccessKeyID"

	ErrBucketAlreadyExists ErrorCode = "BucketAlreadyExists"

	ErrBucketNotEmpty ErrorCode = "BucketNotEmpty"

	ErrIllegalVersioningConfiguration ErrorCode = "IllegalVersioningConfigurationException"

	ErrIncompleteBody ErrorCode = "IncompleteBody"

	ErrIncorrectNumberOfFilesInPostRequest ErrorCode = "IncorrectNumberOfFilesInPostRequest"

	ErrInlineDataTooLarge ErrorCode = "InlineDataTooLarge"

	ErrInvalidArgument ErrorCode = "InvalidArgument"

	ErrInvalidBucketName ErrorCode = "InvalidBucketName"

	ErrInvalidDigest ErrorCode = "InvalidDigest"

	ErrInvalidRange         ErrorCode = "InvalidRange"
	ErrInvalidToken         ErrorCode = "InvalidToken"
	ErrKeyTooLong           ErrorCode = "KeyTooLongError"
	ErrMalformedPOSTRequest ErrorCode = "MalformedPOSTRequest"

	ErrInvalidPart ErrorCode = "InvalidPart"

	ErrInvalidPartOrder ErrorCode = "InvalidPartOrder"

	ErrInvalidURI ErrorCode = "InvalidURI"

	ErrMetadataTooLarge ErrorCode = "MetadataTooLarge"
	ErrMethodNotAllowed ErrorCode = "MethodNotAllowed"
	ErrMalformedXML     ErrorCode = "MalformedXML"

	ErrMissingContentLength ErrorCode = "MissingContentLength"

	ErrNoSuchBucket ErrorCode = "NoSuchBucket"

	ErrNoSuchKey ErrorCode = "NoSuchKey"

	ErrNoSuchUpload ErrorCode = "NoSuchUpload"

	ErrNoSuchVersion ErrorCode = "NoSuchVersion"

	ErrRequestTimeTooSkewed ErrorCode = "RequestTimeTooSkewed"
	ErrTooManyBuckets       ErrorCode = "TooManyBuckets"
	ErrNotImplemented       ErrorCode = "NotImplemented"

	ErrInternal      ErrorCode = "InternalError"
	ErrAuthorization ErrorCode = "NotAuthorization"
)

func (ErrorCode) Error

func (e ErrorCode) Error() string

func (ErrorCode) ErrorCode

func (e ErrorCode) ErrorCode() ErrorCode

func (ErrorCode) Message

func (e ErrorCode) Message() string

func (ErrorCode) Status

func (e ErrorCode) Status() int

type ErrorInvalidArgumentResponse

type ErrorInvalidArgumentResponse struct {
	ErrorResponse

	ArgumentName  string `xml:"ArgumentName"`
	ArgumentValue string `xml:"ArgumentValue"`
}

type ErrorResponse

type ErrorResponse struct {
	XMLName xml.Name `xml:"Error"`

	Code      ErrorCode
	Message   string `xml:",omitempty"`
	RequestID string `xml:"RequestId,omitempty"`
	HostID    string `xml:"HostId,omitempty"`
}

func (*ErrorResponse) Error

func (e *ErrorResponse) Error() string

func (*ErrorResponse) ErrorCode

func (e *ErrorResponse) ErrorCode() ErrorCode

type ErrorResult

type ErrorResult struct {
	XMLName   xml.Name  `xml:"Error"`
	Key       string    `xml:"Key,omitempty"`
	Code      ErrorCode `xml:"Code,omitempty"`
	Message   string    `xml:"Message,omitempty"`
	Resource  string    `xml:"Resource,omitempty"`
	RequestID string    `xml:"RequestId,omitempty"`
}

func ErrorResultFromError

func ErrorResultFromError(err error) ErrorResult

func (ErrorResult) String

func (er ErrorResult) String() string

type GetBucketLocation

type GetBucketLocation struct {
	XMLName            xml.Name `xml:"LocationConstraint"`
	Xmlns              string   `xml:"xmlns,attr"`
	LocationConstraint string   `xml:",chardata"`
}

type InitiateMultipartUpload

type InitiateMultipartUpload struct {
	Bucket   string   `xml:"Bucket"`
	Key      string   `xml:"Key"`
	UploadID UploadID `xml:"UploadId"`
}

type InternalErrorCode

type InternalErrorCode string
const (
	ErrInternalPageNotImplemented InternalErrorCode = "PaginationNotImplemented"
)

func (InternalErrorCode) Error

func (e InternalErrorCode) Error() string

func (InternalErrorCode) ErrorCode

func (e InternalErrorCode) ErrorCode() ErrorCode

type ListBucketPage

type ListBucketPage struct {
	Marker    string
	HasMarker bool

	MaxKeys int64
}

func (ListBucketPage) IsEmpty

func (p ListBucketPage) IsEmpty() bool

type ListBucketResult

type ListBucketResult struct {
	ListBucketResultBase

	Marker string `xml:"Marker"`

	NextMarker string `xml:"NextMarker,omitempty"`
}

type ListBucketResultBase

type ListBucketResultBase struct {
	XMLName xml.Name `xml:"ListBucketResult"`
	Xmlns   string   `xml:"xmlns,attr"`

	Name string `xml:"Name"`

	IsTruncated bool `xml:"IsTruncated"`

	Delimiter string `xml:"Delimiter,omitempty"`

	Prefix string `xml:"Prefix"`

	MaxKeys int64 `xml:"MaxKeys,omitempty"`

	CommonPrefixes []CommonPrefix `xml:"CommonPrefixes,omitempty"`
	Contents       []*Content     `xml:"Contents"`
}

type ListBucketResultV2

type ListBucketResultV2 struct {
	ListBucketResultBase

	ContinuationToken string `xml:"ContinuationToken,omitempty"`

	KeyCount int64 `xml:"KeyCount,omitempty"`

	NextContinuationToken string `xml:"NextContinuationToken,omitempty"`

	StartAfter string `xml:"StartAfter,omitempty"`
}

type ListBucketVersionsResult

type ListBucketVersionsResult struct {
	XMLName        xml.Name       `xml:"ListBucketVersionsResult"`
	Xmlns          string         `xml:"xmlns,attr"`
	Name           string         `xml:"Name"`
	Delimiter      string         `xml:"Delimiter,omitempty"`
	Prefix         string         `xml:"Prefix,omitempty"`
	CommonPrefixes []CommonPrefix `xml:"CommonPrefixes,omitempty"`
	IsTruncated    bool           `xml:"IsTruncated"`
	MaxKeys        int64          `xml:"MaxKeys"`

	KeyMarker string `xml:"KeyMarker,omitempty"`

	NextKeyMarker string `xml:"NextKeyMarker,omitempty"`

	VersionIDMarker VersionID `xml:"VersionIdMarker,omitempty"`

	NextVersionIDMarker VersionID `xml:"NextVersionIdMarker,omitempty"`

	Versions []VersionItem
	// contains filtered or unexported fields
}

type ListMultipartUploadItem

type ListMultipartUploadItem struct {
	Key          string       `xml:"Key"`
	UploadID     UploadID     `xml:"UploadId"`
	Initiator    *UserInfo    `xml:"Initiator,omitempty"`
	Owner        *UserInfo    `xml:"Owner,omitempty"`
	StorageClass StorageClass `xml:"StorageClass,omitempty"`
	Initiated    ContentTime  `xml:"Initiated,omitempty"`
}

type ListMultipartUploadPartItem

type ListMultipartUploadPartItem struct {
	PartNumber   int         `xml:"PartNumber"`
	LastModified ContentTime `xml:"LastModified,omitempty"`
	ETag         string      `xml:"ETag,omitempty"`
	Size         int64       `xml:"Size"`
}

type ListMultipartUploadPartsResult

type ListMultipartUploadPartsResult struct {
	XMLName xml.Name `xml:"ListPartsResult"`

	Bucket               string       `xml:"Bucket"`
	Key                  string       `xml:"Key"`
	UploadID             UploadID     `xml:"UploadId"`
	StorageClass         StorageClass `xml:"StorageClass,omitempty"`
	Initiator            *UserInfo    `xml:"Initiator,omitempty"`
	Owner                *UserInfo    `xml:"Owner,omitempty"`
	PartNumberMarker     int          `xml:"PartNumberMarker"`
	NextPartNumberMarker int          `xml:"NextPartNumberMarker"`
	MaxParts             int64        `xml:"MaxParts"`
	IsTruncated          bool         `xml:"IsTruncated,omitempty"`

	Parts []ListMultipartUploadPartItem `xml:"Part"`
}

type ListMultipartUploadsResult

type ListMultipartUploadsResult struct {
	Bucket string `xml:"Bucket"`

	KeyMarker string `xml:"KeyMarker,omitempty"`

	UploadIDMarker UploadID `xml:"UploadIdMarker,omitempty"`

	NextKeyMarker      string   `xml:"NextKeyMarker,omitempty"`
	NextUploadIDMarker UploadID `xml:"NextUploadIdMarker,omitempty"`

	MaxUploads int64 `xml:"MaxUploads,omitempty"`

	Delimiter string `xml:"Delimiter,omitempty"`

	Prefix string `xml:"Prefix,omitempty"`

	CommonPrefixes []CommonPrefix `xml:"CommonPrefixes,omitempty"`
	IsTruncated    bool           `xml:"IsTruncated,omitempty"`

	Uploads []ListMultipartUploadItem `xml:"Upload"`
}

type LogLevel

type LogLevel string
const (
	LogErr  LogLevel = "ERR"
	LogWarn LogLevel = "WARN"
	LogInfo LogLevel = "INFO"
)

type Logger

type Logger interface {
	Print(level LogLevel, v ...interface{})
}

func DiscardLog

func DiscardLog() Logger

DiscardLog creates a Logger that discards all messages.

func GlobalLog

func GlobalLog(levels ...LogLevel) Logger

GlobalLog creates a Logger that uses the global log.Println() function.

All levels are reported by default. If you pass levels to this function, it will act as a level whitelist.

func StdLog

func StdLog(log *log.Logger, levels ...LogLevel) Logger

StdLog creates a Logger that uses the stdlib's log.Logger type.

All levels are reported by default. If you pass levels to this function, it will act as a level whitelist.

type MFADeleteStatus

type MFADeleteStatus string
const (
	MFADeleteNone     MFADeleteStatus = ""
	MFADeleteEnabled  MFADeleteStatus = "Enabled"
	MFADeleteDisabled MFADeleteStatus = "Disabled"
)

type MultiDeleteResult

type MultiDeleteResult struct {
	XMLName xml.Name      `xml:"DeleteResult"`
	Deleted []ObjectID    `xml:"Deleted"`
	Error   []ErrorResult `xml:",omitempty"`
}

type Object

type Object struct {
	Name           string
	Metadata       map[string]string
	Size           int64
	Contents       io.ReadCloser
	Hash           []byte
	Range          *ObjectRange
	VersionID      VersionID
	IsDeleteMarker bool
}

type ObjectDeleteResult

type ObjectDeleteResult struct {
	// Specifies whether the versioned object that was permanently deleted was
	// (true) or was not (false) a delete marker. In a simple DELETE, this
	// header indicates whether (true) or not (false) a delete marker was
	// created.
	IsDeleteMarker bool

	// Returns the version ID of the delete marker created as a result of the
	// DELETE operation. If you delete a specific object version, the value
	// returned by this header is the version ID of the object version deleted.
	VersionID VersionID
}

type ObjectID

type ObjectID struct {
	Key string `xml:"Key"`

	VersionID string `xml:"VersionId,omitempty" json:"VersionId,omitempty"`
}

type ObjectList

type ObjectList struct {
	CommonPrefixes []CommonPrefix
	Contents       []*Content
	IsTruncated    bool
	NextMarker     string
	// contains filtered or unexported fields
}

func NewObjectList

func NewObjectList() *ObjectList

func (*ObjectList) Add

func (b *ObjectList) Add(item *Content)

func (*ObjectList) AddPrefix

func (b *ObjectList) AddPrefix(prefix string)

type ObjectRange

type ObjectRange struct {
	Start, Length int64
}

type ObjectRangeRequest

type ObjectRangeRequest struct {
	Start, End int64
	FromEnd    bool
}

func (*ObjectRangeRequest) Range

func (o *ObjectRangeRequest) Range(size int64) (*ObjectRange, error)

type Option

type Option func(g *Yts3)

func WithGlobalLog

func WithGlobalLog() Option

func WithHostBucket

func WithHostBucket(enabled bool) Option

func WithIntegrityCheck

func WithIntegrityCheck(check bool) Option

func WithLogger

func WithLogger(logger Logger) Option

func WithMetadataSizeLimit

func WithMetadataSizeLimit(size int) Option

func WithRequestID

func WithRequestID(id uint64) Option

func WithTimeSkewLimit

func WithTimeSkewLimit(skew time.Duration) Option

func WithTimeSource

func WithTimeSource(timeSource TimeSource) Option

func WithUnimplementedPageError

func WithUnimplementedPageError() Option

func WithoutVersioning

func WithoutVersioning() Option

type Prefix

type Prefix struct {
	HasPrefix bool
	Prefix    string

	HasDelimiter bool
	Delimiter    string
}

func NewFolderPrefix

func NewFolderPrefix(prefix string) (p Prefix)

func NewPrefix

func NewPrefix(prefix, delim *string) (p Prefix)

func (Prefix) FilePrefix

func (p Prefix) FilePrefix() (path, remaining string, ok bool)

func (Prefix) Match

func (p Prefix) Match(key string, match *PrefixMatch) (ok bool)

func (Prefix) String

func (p Prefix) String() string

type PrefixMatch

type PrefixMatch struct {
	Key string

	CommonPrefix bool

	MatchedPart string
}

func (*PrefixMatch) AsCommonPrefix

func (match *PrefixMatch) AsCommonPrefix() CommonPrefix

type PutObjectResult

type PutObjectResult struct {
	VersionID VersionID
}

type Storage

type Storage struct {
	XMLName xml.Name  `xml:"ListAllMyBucketsResult"`
	Xmlns   string    `xml:"xmlns,attr"`
	Owner   *UserInfo `xml:"Owner,omitempty"`
	Buckets Buckets   `xml:"Buckets>Bucket"`
}

type StorageClass

type StorageClass string
const (
	StorageStandard StorageClass = "STANDARD"
)

type TimeSource

type TimeSource interface {
	Now() time.Time
	Since(time.Time) time.Duration
}

func DefaultTimeSource

func DefaultTimeSource() TimeSource

type TimeSourceAdvancer

type TimeSourceAdvancer interface {
	TimeSource
	Advance(by time.Duration)
}

func FixedTimeSource

func FixedTimeSource(at time.Time) TimeSourceAdvancer

FixedTimeSource provides a source of time that always returns the specified time.

type UploadID

type UploadID string

type UploadListMarker

type UploadListMarker struct {
	Object string

	UploadID UploadID
}

type UserInfo

type UserInfo struct {
	ID          string `xml:"ID"`
	DisplayName string `xml:"DisplayName"`
}

type Version

type Version struct {
	XMLName      xml.Name    `xml:"Version"`
	Key          string      `xml:"Key"`
	VersionID    VersionID   `xml:"VersionId"`
	IsLatest     bool        `xml:"IsLatest"`
	LastModified ContentTime `xml:"LastModified,omitempty"`
	Size         int64       `xml:"Size"`

	StorageClass StorageClass `xml:"StorageClass"`

	ETag  string    `xml:"ETag"`
	Owner *UserInfo `xml:"Owner,omitempty"`
}

func (Version) GetVersionID

func (v Version) GetVersionID() VersionID

type VersionID

type VersionID string

type VersionItem

type VersionItem interface {
	GetVersionID() VersionID
	// contains filtered or unexported methods
}

type VersionedBackend

type VersionedBackend interface{}

type VersioningConfiguration

type VersioningConfiguration struct {
	XMLName xml.Name `xml:"VersioningConfiguration"`

	Status VersioningStatus `xml:"Status"`

	MFADelete MFADeleteStatus `xml:"MfaDelete"`
}

type VersioningStatus

type VersioningStatus string
const (
	VersioningNone      VersioningStatus = ""
	VersioningEnabled   VersioningStatus = "Enabled"
	VersioningSuspended VersioningStatus = "Suspended"
)

type Yts3

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

func New

func New(backend Backend, options ...Option) *Yts3

func (*Yts3) Server

func (g *Yts3) Server() http.Handler

Jump to

Keyboard shortcuts

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