blobstore

package module
v0.0.0-...-0b6fd76 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2021 License: Apache-2.0 Imports: 2 Imported by: 0

README

wasmCloud Blobstore Actor Interface

This package provides wasmCloud actors with an interface to the blobstore capability provider. Actors using this interface must have the claim wasmcloud:blobstore in order to have permission to communicate with the store.

This generic protocol can be used to support capability providers like local blob storage, Amazon S3, Azure blob storage, Google blob storage, and more.

Sample Actor

package main

import (
	"strings"
	core "github.com/wasmcloud/actor-interfaces/actor-core/go"
	httpserver "github.com/wasmcloud/actor-interfaces/http-server/go"
	blob "github.com/wasmcloud/actor-interfaces/blobstore/go"
)

func main() {
    core.Handlers{HealthRequest: healthRequest}.Register()
    httpserver.Handlers{HandleRequest: handleRequest}.Register()
    blob.Handlers{ReceiveChunk: receiveChunk}.Register()
}

func receiveChunk(chunk blob.FileChunk) error {
    // ReceiveChunk is used to process incoming file chunks, as downloading an entire file
    // may exceed the memory capacity of the WebAssembly module.
    // 
    // This is effectively streaming a file download to the module, so you must use
    // the chunk `Context`, `TotalBytes` and `ChunkBytes` fields to determine
    // when you have received all of the bytes for a file.
    return nil
}

func handleRequest(request httpserver.Request) (httpserver.Response, error) {
	switch method := request.Method; method {
	case "GET":
        return downloadImage()
	case "POST":
		return uploadImage(request.Path, request.Body)
	default:
		return httpserver.Response{
			StatusCode: 400,
			Status:     "Bad Request",
			Body:       nil,
		}, nil
	}
}

func downloadImage() (httpserver.Response, error) {
	blobStore := blob.NewHost("default")
	blobStore.StartDownload("myblob", "folder", 512, nil)
	return httpserver.Response{
		StatusCode: 200,
		Status:     "OK",
		Body:       []byte("Download started"),
	}, nil
}

func uploadImage(path string, imageBytes []byte) (httpserver.Response, error) {
	blobStore := blob.NewHost("default")
    container := blob.Container {
        ID: "folder",
    }
    image := blob.FileChunk {
        SequenceNo: 0,
        Container: container,
        ID: strings.ReplaceAll(path, "/", ""),
        TotalBytes: uint64(len(imageBytes)),
        ChunkSize: uint64(len(imageBytes)),
        Context: nil,
        ChunkBytes: imageBytes,
    }
    blobStore.StartUpload(image)
    blobStore.UploadChunk(image)
    return httpserver.Response{
        StatusCode: 200,
        Status:     "OK",
        Body:       []byte("Uploaded Successfully"),
    }, nil
}

func healthRequest(request core.HealthCheckRequest) (core.HealthCheckResponse, error) {
	return core.HealthCheckResponse{
		Healthy: true,
	}, nil
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Blob

type Blob struct {
	ID        string
	Container Container
	ByteSize  uint64
}

A blob is a representation of an object in a blobstore, similar to a file in a file system.

func DecodeBlob

func DecodeBlob(decoder *msgpack.Decoder) (Blob, error)

func DecodeBlobNullable

func DecodeBlobNullable(decoder *msgpack.Decoder) (*Blob, error)

func (*Blob) Decode

func (o *Blob) Decode(decoder *msgpack.Decoder) error

func (*Blob) Encode

func (o *Blob) Encode(encoder msgpack.Writer) error

type BlobList

type BlobList struct {
	Blobs []Blob
}

A wrapper object around a list of blobs.

func DecodeBlobList

func DecodeBlobList(decoder *msgpack.Decoder) (BlobList, error)

func DecodeBlobListNullable

func DecodeBlobListNullable(decoder *msgpack.Decoder) (*BlobList, error)

func (*BlobList) Decode

func (o *BlobList) Decode(decoder *msgpack.Decoder) error

func (*BlobList) Encode

func (o *BlobList) Encode(encoder msgpack.Writer) error

type BlobstoreResult

type BlobstoreResult struct {
	Success bool
	Error   *string
}

Used to return success and error information for common blobstore operations

func DecodeBlobstoreResult

func DecodeBlobstoreResult(decoder *msgpack.Decoder) (BlobstoreResult, error)

func DecodeBlobstoreResultNullable

func DecodeBlobstoreResultNullable(decoder *msgpack.Decoder) (*BlobstoreResult, error)

func (*BlobstoreResult) Decode

func (o *BlobstoreResult) Decode(decoder *msgpack.Decoder) error

func (*BlobstoreResult) Encode

func (o *BlobstoreResult) Encode(encoder msgpack.Writer) error

type Container

type Container struct {
	ID string
}

A container is a logical grouping of blobs, similar to a directory in a file system.

func DecodeContainer

func DecodeContainer(decoder *msgpack.Decoder) (Container, error)

func DecodeContainerNullable

func DecodeContainerNullable(decoder *msgpack.Decoder) (*Container, error)

func (*Container) Decode

func (o *Container) Decode(decoder *msgpack.Decoder) error

func (*Container) Encode

func (o *Container) Encode(encoder msgpack.Writer) error

type ContainerList

type ContainerList struct {
	Containers []Container
}

A wrapper object around a list of containers.

func DecodeContainerList

func DecodeContainerList(decoder *msgpack.Decoder) (ContainerList, error)

func DecodeContainerListNullable

func DecodeContainerListNullable(decoder *msgpack.Decoder) (*ContainerList, error)

func (*ContainerList) Decode

func (o *ContainerList) Decode(decoder *msgpack.Decoder) error

func (*ContainerList) Encode

func (o *ContainerList) Encode(encoder msgpack.Writer) error

type CreateContainerArgs

type CreateContainerArgs struct {
	ID string
}

func DecodeCreateContainerArgs

func DecodeCreateContainerArgs(decoder *msgpack.Decoder) (CreateContainerArgs, error)

func DecodeCreateContainerArgsNullable

func DecodeCreateContainerArgsNullable(decoder *msgpack.Decoder) (*CreateContainerArgs, error)

func (*CreateContainerArgs) Decode

func (o *CreateContainerArgs) Decode(decoder *msgpack.Decoder) error

func (*CreateContainerArgs) Encode

func (o *CreateContainerArgs) Encode(encoder msgpack.Writer) error

type FileChunk

type FileChunk struct {
	SequenceNo uint64
	Container  Container
	ID         string
	TotalBytes uint64
	ChunkSize  uint64
	Context    *string
	ChunkBytes []byte
}

Represents a single chunk that may comprise part of a file or an entire file. The fields for sequence number, total bytes and chunk bytes should be used to determine the chunk order, as well as the optional context field.

func DecodeFileChunk

func DecodeFileChunk(decoder *msgpack.Decoder) (FileChunk, error)

func DecodeFileChunkNullable

func DecodeFileChunkNullable(decoder *msgpack.Decoder) (*FileChunk, error)

func (*FileChunk) Decode

func (o *FileChunk) Decode(decoder *msgpack.Decoder) error

func (*FileChunk) Encode

func (o *FileChunk) Encode(encoder msgpack.Writer) error

type GetObjectInfoArgs

type GetObjectInfoArgs struct {
	BlobID      string
	ContainerID string
}

func DecodeGetObjectInfoArgs

func DecodeGetObjectInfoArgs(decoder *msgpack.Decoder) (GetObjectInfoArgs, error)

func DecodeGetObjectInfoArgsNullable

func DecodeGetObjectInfoArgsNullable(decoder *msgpack.Decoder) (*GetObjectInfoArgs, error)

func (*GetObjectInfoArgs) Decode

func (o *GetObjectInfoArgs) Decode(decoder *msgpack.Decoder) error

func (*GetObjectInfoArgs) Encode

func (o *GetObjectInfoArgs) Encode(encoder msgpack.Writer) error

type Handlers

type Handlers struct {
	// Defines a handler for incoming chunks forwarded by a wasmcloud:blobstore
	// provider. Chunks may not be received in order.
	ReceiveChunk func(chunk FileChunk) error
}

func (Handlers) Register

func (h Handlers) Register()

type Host

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

func NewHost

func NewHost(binding string) *Host

func (*Host) CreateContainer

func (h *Host) CreateContainer(id string) (Container, error)

Create a container in a blobstore. Returns the container created if successful

func (*Host) GetObjectInfo

func (h *Host) GetObjectInfo(blobID string, containerID string) (Blob, error)

Retreives information about a blob

func (*Host) ListObjects

func (h *Host) ListObjects(containerID string) (BlobList, error)

Returns a list of blobs that are present in the specified container

func (*Host) RemoveContainer

func (h *Host) RemoveContainer(id string) (BlobstoreResult, error)

Remove a container from a blobstore

func (*Host) RemoveObject

func (h *Host) RemoveObject(id string, containerID string) (BlobstoreResult, error)

Remove an object from a blobstore

func (*Host) StartDownload

func (h *Host) StartDownload(blobID string, containerID string, chunkSize uint64, context *string) (BlobstoreResult, error)

Issue a request to start a download from a blobstore. Chunks will be sent to the function that's registered with the ReceiveChunk operation.

func (*Host) StartUpload

func (h *Host) StartUpload(chunk FileChunk) (BlobstoreResult, error)

Begin the upload process with the first chunk of a full file. Subsequent chunks should be uploaded with the UploadChunk operation.

func (*Host) UploadChunk

func (h *Host) UploadChunk(chunk FileChunk) (BlobstoreResult, error)

Upload a file chunk to a blobstore, which may only be part of a full file. This must be called AFTER the StartUpload operation. Chunks should be small, as memory over a few megabytes may exceed the wasm memory allocation.

type ListObjectsArgs

type ListObjectsArgs struct {
	ContainerID string
}

func DecodeListObjectsArgs

func DecodeListObjectsArgs(decoder *msgpack.Decoder) (ListObjectsArgs, error)

func DecodeListObjectsArgsNullable

func DecodeListObjectsArgsNullable(decoder *msgpack.Decoder) (*ListObjectsArgs, error)

func (*ListObjectsArgs) Decode

func (o *ListObjectsArgs) Decode(decoder *msgpack.Decoder) error

func (*ListObjectsArgs) Encode

func (o *ListObjectsArgs) Encode(encoder msgpack.Writer) error

type ReceiveChunkArgs

type ReceiveChunkArgs struct {
	Chunk FileChunk
}

func DecodeReceiveChunkArgs

func DecodeReceiveChunkArgs(decoder *msgpack.Decoder) (ReceiveChunkArgs, error)

func DecodeReceiveChunkArgsNullable

func DecodeReceiveChunkArgsNullable(decoder *msgpack.Decoder) (*ReceiveChunkArgs, error)

func (*ReceiveChunkArgs) Decode

func (o *ReceiveChunkArgs) Decode(decoder *msgpack.Decoder) error

func (*ReceiveChunkArgs) Encode

func (o *ReceiveChunkArgs) Encode(encoder msgpack.Writer) error

type RemoveContainerArgs

type RemoveContainerArgs struct {
	ID string
}

func DecodeRemoveContainerArgs

func DecodeRemoveContainerArgs(decoder *msgpack.Decoder) (RemoveContainerArgs, error)

func DecodeRemoveContainerArgsNullable

func DecodeRemoveContainerArgsNullable(decoder *msgpack.Decoder) (*RemoveContainerArgs, error)

func (*RemoveContainerArgs) Decode

func (o *RemoveContainerArgs) Decode(decoder *msgpack.Decoder) error

func (*RemoveContainerArgs) Encode

func (o *RemoveContainerArgs) Encode(encoder msgpack.Writer) error

type RemoveObjectArgs

type RemoveObjectArgs struct {
	ID          string
	ContainerID string
}

func DecodeRemoveObjectArgs

func DecodeRemoveObjectArgs(decoder *msgpack.Decoder) (RemoveObjectArgs, error)

func DecodeRemoveObjectArgsNullable

func DecodeRemoveObjectArgsNullable(decoder *msgpack.Decoder) (*RemoveObjectArgs, error)

func (*RemoveObjectArgs) Decode

func (o *RemoveObjectArgs) Decode(decoder *msgpack.Decoder) error

func (*RemoveObjectArgs) Encode

func (o *RemoveObjectArgs) Encode(encoder msgpack.Writer) error

type StartDownloadArgs

type StartDownloadArgs struct {
	BlobID      string
	ContainerID string
	ChunkSize   uint64
	Context     *string
}

func DecodeStartDownloadArgs

func DecodeStartDownloadArgs(decoder *msgpack.Decoder) (StartDownloadArgs, error)

func DecodeStartDownloadArgsNullable

func DecodeStartDownloadArgsNullable(decoder *msgpack.Decoder) (*StartDownloadArgs, error)

func (*StartDownloadArgs) Decode

func (o *StartDownloadArgs) Decode(decoder *msgpack.Decoder) error

func (*StartDownloadArgs) Encode

func (o *StartDownloadArgs) Encode(encoder msgpack.Writer) error

type StartUploadArgs

type StartUploadArgs struct {
	Chunk FileChunk
}

func DecodeStartUploadArgs

func DecodeStartUploadArgs(decoder *msgpack.Decoder) (StartUploadArgs, error)

func DecodeStartUploadArgsNullable

func DecodeStartUploadArgsNullable(decoder *msgpack.Decoder) (*StartUploadArgs, error)

func (*StartUploadArgs) Decode

func (o *StartUploadArgs) Decode(decoder *msgpack.Decoder) error

func (*StartUploadArgs) Encode

func (o *StartUploadArgs) Encode(encoder msgpack.Writer) error

type Transfer

type Transfer struct {
	BlobID      string
	Container   Container
	ChunkSize   uint64
	TotalSize   uint64
	TotalChunks uint64
	Context     *string
}

func DecodeTransfer

func DecodeTransfer(decoder *msgpack.Decoder) (Transfer, error)

func DecodeTransferNullable

func DecodeTransferNullable(decoder *msgpack.Decoder) (*Transfer, error)

func (*Transfer) Decode

func (o *Transfer) Decode(decoder *msgpack.Decoder) error

func (*Transfer) Encode

func (o *Transfer) Encode(encoder msgpack.Writer) error

type UploadChunkArgs

type UploadChunkArgs struct {
	Chunk FileChunk
}

func DecodeUploadChunkArgs

func DecodeUploadChunkArgs(decoder *msgpack.Decoder) (UploadChunkArgs, error)

func DecodeUploadChunkArgsNullable

func DecodeUploadChunkArgsNullable(decoder *msgpack.Decoder) (*UploadChunkArgs, error)

func (*UploadChunkArgs) Decode

func (o *UploadChunkArgs) Decode(decoder *msgpack.Decoder) error

func (*UploadChunkArgs) Encode

func (o *UploadChunkArgs) Encode(encoder msgpack.Writer) error

Jump to

Keyboard shortcuts

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