ls3

package module
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2022 License: MIT Imports: 26 Imported by: 0

README

LS3

Lightweight read-only S3 compatible object storage interface for local filesystems.

Much like MinIO except simplified to only provide read access to a local directory without any persistent state.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	AccessDenied                 = ErrorCode{Code: "AccessDenied", StatusCode: 403}
	InvalidAccessKeyId           = ErrorCode{Code: "InvalidAccessKeyId", StatusCode: 403}
	SignatureDoesNotMatch        = ErrorCode{Code: "SignatureDoesNotMatch", StatusCode: 403}
	MethodNotAllowed             = ErrorCode{Code: "MethodNotAllowed", StatusCode: 405}
	InvalidRequest               = ErrorCode{Code: "InvalidRequest", StatusCode: 400}
	ExpiredToken                 = ErrorCode{Code: "ExpiredToken", StatusCode: 400}
	InvalidArgument              = ErrorCode{Code: "InvalidArgument", StatusCode: 400}
	BadDigest                    = ErrorCode{Code: "BadDigest", StatusCode: 400}
	NoSuchKey                    = ErrorCode{Code: "NoSuchKey", StatusCode: 404}
	MissingSecurityHeader        = ErrorCode{Code: "MissingSecurityHeader", StatusCode: 400}
	InvalidToken                 = ErrorCode{Code: "InvalidToken", StatusCode: 400}
	InvalidObjectState           = ErrorCode{Code: "InvalidObjectState", StatusCode: 403}
	InvalidRange                 = ErrorCode{Code: "InvalidRange", StatusCode: 416}
	NoSuchBucket                 = ErrorCode{Code: "NoSuchBucket", StatusCode: 404}
	InvalidBucketState           = ErrorCode{Code: "InvalidBucketState", StatusCode: 409}
	InternalError                = ErrorCode{Code: "InternalError", StatusCode: 500}
	MalformedXML                 = ErrorCode{Code: "MalformedXML", StatusCode: 400}
	AuthorizationHeaderMalformed = ErrorCode{Code: "AuthorizationHeaderMalformed", StatusCode: 400}
	InvalidSecurity              = ErrorCode{Code: "InvalidSecurity", StatusCode: 403}
)

Functions

This section is empty.

Types

type Authorization

type Authorization struct {
	Credentials   Credential
	SignedHeaders []string
	Signature     []byte // raw decoded hex
}

func ParseAuthorizationHeader added in v0.9.0

func ParseAuthorizationHeader(hdr string) (*Authorization, error)

ParseAuthorizationHeader parses the contents of the given Authorization header. Returns a non-nil *ErrInvalidAuthorizationHeader when an invalid header is given.

func (Authorization) AppendFormat

func (a Authorization) AppendFormat(b []byte) []byte

type BucketFilesystemProvider added in v0.5.0

type BucketFilesystemProvider interface {
	// ListBuckets lists all available buckets in the provider.
	ListBuckets() ([]string, error)

	// Open returns a filesystem for a given bucket name.
	Open(bucket string) (fs.FS, error)
}

type BucketIterator added in v0.6.0

type BucketIterator struct {
	IsTruncated bool
	Continue    string
	// contains filtered or unexported fields
}

func NewBucketIterator added in v0.6.0

func NewBucketIterator(fs fs.FS) *BucketIterator

func (*BucketIterator) CommonPrefixes added in v0.6.0

func (it *BucketIterator) CommonPrefixes() (prefixes []CommonPrefixes)

func (*BucketIterator) PrefixScan added in v0.6.0

func (it *BucketIterator) PrefixScan(prefix string, delimiter string, objectKeyEncoding bool, maxKeys int) ([]Contents, error)

func (*BucketIterator) Seek added in v0.6.0

func (it *BucketIterator) Seek(after string)

Seek sets the starting object key to begin seeking during the next PrefixScan. It set, all objects will be discarded until the first occurrence of after.

type CommonPrefixes added in v0.6.0

type CommonPrefixes struct {
	Prefix string
}

type Contents added in v0.6.0

type Contents struct {
	ChecksumAlgorithm string
	ETag              string
	Key               string
	LastModified      time.Time
	Size              int
	StorageClass      string
}

type Credential

type Credential struct {
	AccessKeyID string
	Date        time.Time
	Region      string
	Service     string
	Type        string
}

func ParseCredential

func ParseCredential(value string) (*Credential, error)

func (Credential) AppendFormat

func (c Credential) AppendFormat(b []byte) []byte

type Error

type Error struct {
	ErrorCode
	Message string `xml:"Message"`
}

func ErrorFrom

func ErrorFrom(err error) *Error

func (*Error) Error

func (e *Error) Error() string

type ErrorCode

type ErrorCode struct {
	Code       string `xml:"Code"`
	StatusCode int    `xml:"-"`
}

type Method

type Method func(ctx *RequestContext) *Error

type Object

type Object struct {
	io.ReadCloser

	Size         int64
	Range        *http_range.Range
	LastModified time.Time
	// ETag represents the ETag field of the Object.
	// It is always empty.
	ETag string
}

type RequestContext

type RequestContext struct {
	*zap.Logger
	ID         uuid.UUID
	Bucket     string
	Filesystem fs.FS
	Request    *http.Request
	// contains filtered or unexported fields
}

func (*RequestContext) Header

func (ctx *RequestContext) Header() http.Header

func (*RequestContext) SendKnownError

func (ctx *RequestContext) SendKnownError(err *Error)

SendKnownError replies to the caller with a concrete *Error type using the standard Amazon S3 XML error encoding.

func (*RequestContext) SendPlain

func (ctx *RequestContext) SendPlain(statusCode int) io.Writer

func (*RequestContext) SendXML

func (ctx *RequestContext) SendXML(statusCode int, payload any)

type Server

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

func NewServer

func NewServer(log *zap.Logger, signer Signer, buckets BucketFilesystemProvider, domain string) *Server

func (*Server) GetBucketLocation

func (s *Server) GetBucketLocation(ctx *RequestContext) *Error

func (*Server) GetObject

func (s *Server) GetObject(ctx *RequestContext) *Error

func (*Server) HeadBucket

func (s *Server) HeadBucket(ctx *RequestContext) *Error

func (*Server) HeadObject

func (s *Server) HeadObject(ctx *RequestContext) *Error

func (*Server) ListBuckets added in v0.5.0

func (s *Server) ListBuckets(ctx *RequestContext) *Error

func (*Server) ListObjects added in v0.6.0

func (s *Server) ListObjects(ctx *RequestContext) *Error

func (*Server) ListObjectsV2

func (s *Server) ListObjectsV2(ctx *RequestContext) *Error

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(rw http.ResponseWriter, r *http.Request)

type SignAWSV4 added in v0.2.0

type SignAWSV4 struct {
	Region          string
	AccessKeyID     string
	SecretAccessKey string
	// contains filtered or unexported fields
}

func (SignAWSV4) Sign added in v0.2.0

func (s SignAWSV4) Sign(r *http.Request, payload []byte) error

func (SignAWSV4) SigningRegion added in v0.2.0

func (s SignAWSV4) SigningRegion() string

func (SignAWSV4) Verify added in v0.2.0

func (s SignAWSV4) Verify(r *http.Request) error

func (SignAWSV4) VerifyHeaders added in v0.9.0

func (s SignAWSV4) VerifyHeaders(r *http.Request) error

func (SignAWSV4) VerifyQuery added in v0.9.0

func (s SignAWSV4) VerifyQuery(r *http.Request) error

type Signer

type Signer interface {
	// SigningRegion returns the region string that is used to verify requests.
	SigningRegion() string

	// Sign computes and signs the given HTTP request using the given request payload.
	// payload should be the contents of r.Body.
	Sign(r *http.Request, payload []byte) error

	// Verify verifies the authorization and request signature present in the HTTP request.
	// Verify should return a non-nil error on verification failure, ideally this should contain the underlying type *Error.
	// If Verify reads data from r.Body, it must ensure that the data can be re-read from r if Verify returns a nil error.
	Verify(r *http.Request) error
}

A Signer is a type capable of signing and verifying the authorization and request signature present in an HTTP request.

type SingleBucketFilesystem added in v0.2.0

type SingleBucketFilesystem struct {
	fs.FS
}

SingleBucketFilesystem implements BucketFilesystemProvider that always returns the same filesystem for any bucket name provided.

func (*SingleBucketFilesystem) ListBuckets added in v0.5.0

func (p *SingleBucketFilesystem) ListBuckets() ([]string, error)

ListBuckets always returns the same bucket name. The actual name doesn't matter, as the provider will always return the same filesystem.

func (*SingleBucketFilesystem) Open added in v0.5.0

func (p *SingleBucketFilesystem) Open(_ string) (fs.FS, error)

type SubdirBucketFilesystem added in v0.2.0

type SubdirBucketFilesystem struct {
	fs.FS
}

func (*SubdirBucketFilesystem) ListBuckets added in v0.5.0

func (p *SubdirBucketFilesystem) ListBuckets() ([]string, error)

ListBuckets returns all subdirectories of the base filesystem.

func (*SubdirBucketFilesystem) Open added in v0.5.0

func (p *SubdirBucketFilesystem) Open(bucket string) (fs.FS, error)

Open returns a subdirectory of the base filesystem for each bucket. The error NoSuchBucket is returned if fs.Stat of the bucket path returns an error. The error InvalidBucketState is returned if fs.Sub returns an error.

Directories

Path Synopsis
cmd
ls3 command

Jump to

Keyboard shortcuts

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