Documentation
¶
Overview ¶
Package fs implements bsw.BlockStorageWrapper for the local file system.
Service issues signed tokens for upload and download. A token is base64url(payload) + "." + base64url(HMAC-SHA256(payload)), where payload holds the operation, bucket, key and expiration time. Tokens can not be forged or changed without the key, and an upload token can not be used for download and vice versa.
FileSystemStorageServer serves the upload and download endpoints that accept these tokens and store objects under a base directory.
On case-insensitive file systems names that differ only in case refer to the same file.
Index ¶
- Constants
- Variables
- type AwsCompletedPartdeprecated
- type Config
- type DownloadHandler
- type FileSystemStorageServer
- func (s *FileSystemStorageServer) Endpoints() []vatel.Endpoint
- func (s *FileSystemStorageServer) OpenObject(o *bsw.Object) (*os.File, int64, error)
- func (s *FileSystemStorageServer) ReadObjectTo(o *bsw.Object, w io.Writer) error
- func (s *FileSystemStorageServer) WriteObject(o *bsw.Object, r io.Reader) error
- type Op
- type Service
- func (s *Service) CompleteMultipartUpload(o *bsw.Object, uploadID string, parts []bsw.CompletedPart) error
- func (s *Service) DecodeSignedURL(token string, op Op) (*bsw.Object, error)
- func (s *Service) Name() string
- func (s *Service) PreSignGetObjectURL(o *bsw.Object, timeout time.Duration) (string, error)
- func (s *Service) PreSignMultipartObjectURL(o *bsw.Object, timeout time.Duration) ([]string, string, error)
- func (s *Service) PreSignPutObjectURL(o *bsw.Object, timeout time.Duration) (string, error)
- type SignedURLDecoder
- type UploadHandler
Constants ¶
const MinKeyLen = 32
MinKeyLen is the minimal length of Config.URLEncryptionKey in bytes.
Variables ¶
var ( ErrBasePathNotFound = errors.Template("path not exist"). Code("BSW-0401").StatusCode(500).Severity(errors.Critical) ErrInvalidSignedURL = errors.Template("invalid signed URL"). Code("BSW-0402").StatusCode(403).Severity(errors.Tiny) ErrValidation = errors.Template("validation failed"). Code("BSW-0403").StatusCode(400).Severity(errors.Tiny) ErrSignedURLExpired = errors.Template("signed URL is expired"). Code("BSW-0404").StatusCode(403).Severity(errors.Tiny) ErrObjectNotFound = errors.Template("object not found"). Code("BSW-0405").StatusCode(404).Severity(errors.Tiny) ErrStorage = errors.Template("file storage failure"). Code("BSW-0406").StatusCode(500).Severity(errors.Medium) )
Functions ¶
This section is empty.
Types ¶
type AwsCompletedPart
deprecated
type Config ¶
type Config struct {
// URLEncryptionKey is the secret used to sign tokens with HMAC-SHA256.
// It must be at least MinKeyLen bytes long. The name is kept for
// compatibility: tokens are signed, not encrypted.
URLEncryptionKey string `json:"urlEncryptionKey"`
// BasePath is the directory objects are stored in. It must exist.
BasePath string `json:"basePath"`
}
Config holds file storage settings.
type DownloadHandler ¶
type DownloadHandler struct {
// contains filtered or unexported fields
}
DownloadHandler handles GET /api/v1/bos/download.
func (*DownloadHandler) Handle ¶
func (c *DownloadHandler) Handle(ctx vatel.Context) error
Handle writes the file to the response.
func (*DownloadHandler) Input ¶
func (c *DownloadHandler) Input() any
Input returns the request parameters.
type FileSystemStorageServer ¶
type FileSystemStorageServer struct {
// contains filtered or unexported fields
}
FileSystemStorageServer serves upload and download endpoints and stores objects as files: <basePath>/<bucket>/<key>.
func NewFileSystemStorage ¶
func NewFileSystemStorage(sud SignedURLDecoder, basePath string) *FileSystemStorageServer
NewFileSystemStorage returns a server storing objects under basePath.
func (*FileSystemStorageServer) Endpoints ¶
func (s *FileSystemStorageServer) Endpoints() []vatel.Endpoint
Endpoints returns the upload and download endpoints.
POST /api/v1/bos/upload?dest=<token> expects a multipart form with the file in the "file" field. The request body size is limited by the fasthttp server settings (MaxRequestBodySize).
GET /api/v1/bos/download?src=<token> returns the file.
func (*FileSystemStorageServer) OpenObject ¶ added in v0.2.0
OpenObject opens the object file for reading and returns its size. It returns ErrObjectNotFound if the file does not exist.
func (*FileSystemStorageServer) ReadObjectTo ¶
ReadObjectTo copies the object file to w.
func (*FileSystemStorageServer) WriteObject ¶
WriteObject writes r to the object file. Existing content is replaced atomically: data is written to a temporary file which is then renamed.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service signs and verifies upload and download tokens.
func NewFileStorageWrapper ¶ added in v0.0.2
NewFileStorageWrapper returns a service. cfg is copied.
func (*Service) CompleteMultipartUpload ¶
func (s *Service) CompleteMultipartUpload(o *bsw.Object, uploadID string, parts []bsw.CompletedPart) error
CompleteMultipartUpload is not supported.
func (*Service) DecodeSignedURL ¶
DecodeSignedURL verifies the token and returns the object it allows operation op for. It returns ErrInvalidSignedURL if the token is malformed, forged or issued for another operation, and ErrSignedURLExpired if it is expired.
func (*Service) PreSignGetObjectURL ¶
PreSignGetObjectURL returns a signed token for download. The token is passed to the download endpoint in the "src" parameter.
type SignedURLDecoder ¶
SignedURLDecoder verifies tokens. *Service implements it.
type UploadHandler ¶
type UploadHandler struct {
// contains filtered or unexported fields
}
UploadHandler handles POST /api/v1/bos/upload.
It does not implement vatel.Inputer on purpose: vatel decodes the body of a POST request with Input() as JSON, while upload is a multipart form. The token is read with FormValue from the query string or the form.