resourceio

package
v3.0.16 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PermissionFSWorkspaceRead    = "fs.workspace.read"
	PermissionFSWorkspaceWrite   = "fs.workspace.write"
	PermissionFSHomeRead         = "fs.home.read"
	PermissionFSHomeWrite        = "fs.home.write"
	PermissionFSEnvironmentRead  = "fs.environment.read"
	PermissionFSEnvironmentWrite = "fs.environment.write"
	PermissionNetworkClient      = "network.client"
	PermissionNetworkListen      = "network.listen"
)
View Source
const (
	IOFlagEOF         uint32 = 1 << 0
	IOFlagText        uint32 = 1 << 1
	IOFlagBinary      uint32 = 1 << 2
	IOFlagMessageEnd  uint32 = 1 << 3
	IOFlagDatagramEnd uint32 = 1 << 4
)
View Source
const (
	MinimumFileHandles      = 64
	MinimumConnections      = 32
	MinimumWatchesListeners = 8
)
View Source
const MaxIOChunkBytes = 64 << 10
View Source
const PluginAPI uint16 = 1

Variables

View Source
var (
	ErrCrossDevice      = errors.New("cross-device operation is not allowed")
	ErrUnsafeFile       = errors.New("filesystem object is unsafe")
	ErrInvalidOptions   = errors.New("file open options are invalid")
	ErrMountUnavailable = errors.New("filesystem mount is unavailable")
	ErrWatchUnsupported = errors.New("filesystem watch is unavailable")
)
View Source
var (
	ErrInvalidHandle  = errors.New("resource handle is invalid")
	ErrResourceClosed = errors.New("resource is closed")
	ErrOwnerMismatch  = errors.New("resource handle owner mismatch")
	ErrResourceLimit  = errors.New("resource limit exceeded")
)
View Source
var ErrInvalidURI = errors.New("invalid redevfs URI")
View Source
var ErrRedirectRequiresReplay = errors.New("redirect requires request body replay")

Functions

func StableError

func StableError(err error) (string, bool)

StableError projects broker failures onto the closed Worker API error set.

func Sync

func Sync(resource io.Closer) error

Types

type ChunkReader

type ChunkReader interface {
	ReadChunk(context.Context, []byte) (int, uint32, error)
}

type ChunkWriter

type ChunkWriter interface {
	WriteChunk(context.Context, []byte, uint32) (int, error)
}

type DirectoryEntry

type DirectoryEntry struct {
	Name string   `json:"name"`
	URI  string   `json:"uri"`
	Kind FileKind `json:"kind"`
}

type DirectoryPage

type DirectoryPage struct {
	Entries []DirectoryEntry `json:"entries"`
	EOF     bool             `json:"eof"`
}

type DirectoryStream

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

func (*DirectoryStream) Close

func (stream *DirectoryStream) Close() error

func (*DirectoryStream) Next

func (stream *DirectoryStream) Next(limit int) (DirectoryPage, error)

type Entry

type Entry struct {
	ID       HandleID
	Owner    Owner
	Kind     Kind
	Resource io.Closer
	// contains filtered or unexported fields
}

type FileKind

type FileKind string
const (
	FileKindFile      FileKind = "file"
	FileKindDirectory FileKind = "directory"
	FileKindSymlink   FileKind = "symlink"
	FileKindOther     FileKind = "other"
)

type FileStat

type FileStat struct {
	URI            string   `json:"uri"`
	Kind           FileKind `json:"kind"`
	Size           int64    `json:"size"`
	Mode           uint32   `json:"mode"`
	ModifiedUnixMS int64    `json:"modified_unix_ms"`
	CreatedUnixMS  *int64   `json:"created_unix_ms,omitempty"`
}

type FullDuplexResource

type FullDuplexResource interface {
	FullDuplexResource()
}

type HTTPRequest

type HTTPRequest struct {
	Method    string
	URL       string
	Headers   []Header
	Redirect  RedirectMode
	Timeout   time.Duration
	Authorize func(context.Context, *url.URL) error
}

type HTTPResponse

type HTTPResponse struct {
	Status   int
	Headers  []Header
	FinalURL string
	Body     io.ReadCloser
}

type HTTPUpload

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

func BeginHTTP

func BeginHTTP(ctx context.Context, request HTTPRequest) (*HTTPUpload, error)

func (*HTTPUpload) Abort

func (upload *HTTPUpload) Abort(cause error) error

func (*HTTPUpload) Close

func (upload *HTTPUpload) Close() error

func (*HTTPUpload) Finish

func (upload *HTTPUpload) Finish() (*HTTPResponse, error)

func (*HTTPUpload) Write

func (upload *HTTPUpload) Write(value []byte) (int, error)

func (*HTTPUpload) WriteChunk

func (upload *HTTPUpload) WriteChunk(ctx context.Context, value []byte, flags uint32) (int, error)

type HandleID

type HandleID uint64
type Header struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

type Invocation

type Invocation struct {
	Owner       Owner
	Plugin      Plugin
	Permissions map[string]bool
	CanRead     bool
	CanWrite    bool
}

type Kind

type Kind string
const (
	KindFile        Kind = "file"
	KindDirectory   Kind = "directory"
	KindWatch       Kind = "watch"
	KindHTTPUpload  Kind = "http_upload"
	KindHTTPBody    Kind = "http_body"
	KindWebSocket   Kind = "websocket"
	KindTCP         Kind = "tcp"
	KindTCPListener Kind = "tcp_listener"
	KindUDP         Kind = "udp"
)

type Lifetime

type Lifetime string
const (
	LifetimeInvocation Lifetime = "invocation"
	LifetimeSession    Lifetime = "session"
)

type Limits

type Limits struct {
	FileHandles      int
	Connections      int
	WatchesListeners int
}

func DefaultLimits

func DefaultLimits() Limits

type Mount

type Mount struct {
	ID       string
	Root     *os.Root
	ReadOnly bool
	Scope    sessionctx.ResourceScope
}

func OpenMount

func OpenMount(id, path string, readOnly bool, scope sessionctx.ResourceScope) (Mount, error)

func (Mount) Close

func (mount Mount) Close() error

func (Mount) Copy

func (mount Mount) Copy(from, to URI, overwrite bool, mode fs.FileMode) error

func (Mount) Mkdir

func (mount Mount) Mkdir(uri URI, recursive bool, mode fs.FileMode) error

func (Mount) OpenDirectory

func (mount Mount) OpenDirectory(uri URI) (*DirectoryStream, error)

func (Mount) OpenFile

func (mount Mount) OpenFile(uri URI, options OpenOptions) (*os.File, error)

func (Mount) OpenWatch

func (mount Mount) OpenWatch(uri URI) (*WatchStream, error)

func (Mount) Remove

func (mount Mount) Remove(uri URI, recursive bool) error

func (Mount) Rename

func (mount Mount) Rename(from, to URI, overwrite bool) error

func (Mount) SetTimes

func (mount Mount) SetTimes(uri URI, accessed, modified time.Time) error

func (Mount) Stat

func (mount Mount) Stat(uri URI, followSymlinks bool) (FileStat, error)

type MountResolver

type MountResolver interface {
	ResolveMount(context.Context, Invocation, string) (MountSpec, error)
	ListMounts(context.Context, Invocation) ([]MountSpec, error)
}

type MountSpec

type MountSpec struct {
	ID       string
	Path     string
	ReadOnly bool
}

type NetworkAuthorization

type NetworkAuthorization struct {
	Invocation  Invocation
	Operation   string
	Destination *url.URL
	Listen      bool
}

type NetworkAuthorizer

type NetworkAuthorizer interface {
	AuthorizeNetwork(context.Context, NetworkAuthorization) error
}

type OpenOptions

type OpenOptions struct {
	Read      bool        `json:"read"`
	Write     bool        `json:"write"`
	Create    bool        `json:"create"`
	CreateNew bool        `json:"create_new"`
	Truncate  bool        `json:"truncate"`
	Append    bool        `json:"append"`
	Mode      fs.FileMode `json:"mode,omitempty"`
}

type OwnedChunkWriter

type OwnedChunkWriter interface {
	WriteOwnedChunk(context.Context, Owner, []byte, uint32) (int, error)
}

type Owner

type Owner struct {
	PluginInstanceID   string
	ActiveFingerprint  string
	Scope              sessionctx.ResourceScope
	Session            sessionctx.SessionScope
	RuntimeGeneration  string
	ManagementRevision uint64
	RevokeEpoch        uint64
	InvocationID       string
	Lifetime           Lifetime
}

type Plugin

type Plugin struct {
	ID         string
	InstanceID string
	Version    string
}

type RedirectMode

type RedirectMode string
const (
	RedirectFollow RedirectMode = "follow"
	RedirectManual RedirectMode = "manual"
	RedirectError  RedirectMode = "error"
)

type Service

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

func NewService

func NewService(table *Table, mounts MountResolver, network NetworkAuthorizer) (*Service, error)

func (*Service) Close

func (service *Service) Close(invocation Invocation, handle uint64) error

func (*Service) Control

func (service *Service) Control(ctx context.Context, invocation Invocation, raw []byte) ([]byte, error)

func (*Service) Read

func (service *Service) Read(ctx context.Context, invocation Invocation, handle uint64, destination []byte) (int, uint32, error)

func (*Service) Revoke

func (service *Service) Revoke(predicate func(Owner) bool) error

func (*Service) Seek

func (service *Service) Seek(invocation Invocation, handle uint64, offset int64, whence int) (int64, error)

func (*Service) Write

func (service *Service) Write(ctx context.Context, invocation Invocation, handle uint64, source []byte, flags uint32) (int, error)

type TCPConnectOptions

type TCPConnectOptions struct {
	Address   string
	Timeout   time.Duration
	NoDelay   bool
	KeepAlive time.Duration
}

type TCPListener

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

func ListenTCP

func ListenTCP(ctx context.Context, address string) (*TCPListener, error)

func (*TCPListener) Accept

func (listener *TCPListener) Accept(ctx context.Context, noDelay bool, keepAlive time.Duration) (*TCPStream, error)

func (*TCPListener) Address

func (listener *TCPListener) Address() string

func (*TCPListener) Close

func (listener *TCPListener) Close() error

type TCPShutdown

type TCPShutdown string
const (
	TCPShutdownRead  TCPShutdown = "read"
	TCPShutdownWrite TCPShutdown = "write"
	TCPShutdownBoth  TCPShutdown = "both"
)

type TCPStream

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

func OpenTCP

func OpenTCP(ctx context.Context, options TCPConnectOptions) (*TCPStream, error)

func (*TCPStream) Close

func (stream *TCPStream) Close() error

func (*TCPStream) FullDuplexResource

func (*TCPStream) FullDuplexResource()

func (*TCPStream) Read

func (stream *TCPStream) Read(destination []byte) (int, error)

func (*TCPStream) Shutdown

func (stream *TCPStream) Shutdown(direction TCPShutdown) error

func (*TCPStream) Write

func (stream *TCPStream) Write(source []byte) (int, error)

type Table

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

func NewTable

func NewTable(max int) (*Table, error)

func NewTableWithLimits

func NewTableWithLimits(limits Limits) (*Table, error)

func (*Table) Close

func (table *Table) Close(id HandleID, owner Owner) error

func (*Table) Len

func (table *Table) Len() int

func (*Table) Open

func (table *Table) Open(owner Owner, kind Kind, resource io.Closer) (HandleID, error)

func (*Table) Read

func (table *Table) Read(ctx context.Context, id HandleID, owner Owner, destination []byte) (int, error)

func (*Table) ReadChunk

func (table *Table) ReadChunk(ctx context.Context, id HandleID, owner Owner, destination []byte) (int, uint32, error)

func (*Table) Revoke

func (table *Table) Revoke(predicate func(Owner) bool) error

func (*Table) Seek

func (table *Table) Seek(id HandleID, owner Owner, offset int64, whence int) (int64, error)

func (*Table) Use

func (table *Table) Use(id HandleID, owner Owner, kind Kind, use func(io.Closer) error) error

func (*Table) UseControl

func (table *Table) UseControl(id HandleID, owner Owner, kind Kind, use func(io.Closer) error) error

UseControl serializes control operations without waiting for a blocked read or write on a full-duplex resource.

func (*Table) Write

func (table *Table) Write(ctx context.Context, id HandleID, owner Owner, source []byte) (int, error)

func (*Table) WriteChunk

func (table *Table) WriteChunk(ctx context.Context, id HandleID, owner Owner, source []byte, flags uint32) (int, error)

type UDPResource

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

func OpenUDP

func OpenUDP(ctx context.Context, address string, timeout time.Duration) (*UDPResource, error)

func (*UDPResource) Close

func (resource *UDPResource) Close() error

func (*UDPResource) FullDuplexResource

func (*UDPResource) FullDuplexResource()

func (*UDPResource) ReadChunk

func (resource *UDPResource) ReadChunk(ctx context.Context, destination []byte) (int, uint32, error)

func (*UDPResource) WriteChunk

func (resource *UDPResource) WriteChunk(ctx context.Context, source []byte, flags uint32) (int, error)

type URI

type URI struct {
	MountID string
	Path    string
}

func ParseURI

func ParseURI(raw string) (URI, error)

func (URI) String

func (uri URI) String() string

type WatchEvent

type WatchEvent struct {
	Sequence    uint64    `json:"sequence"`
	Kind        WatchKind `json:"kind"`
	URI         string    `json:"uri"`
	PreviousURI string    `json:"previous_uri,omitempty"`
}

type WatchKind

type WatchKind string
const (
	WatchKindCreate   WatchKind = "create"
	WatchKindChange   WatchKind = "change"
	WatchKindDelete   WatchKind = "delete"
	WatchKindRename   WatchKind = "rename"
	WatchKindOverflow WatchKind = "overflow"
)

type WatchStream

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

func (*WatchStream) Close

func (stream *WatchStream) Close() error

func (*WatchStream) Next

func (stream *WatchStream) Next(ctx context.Context, timeout time.Duration) (WatchEvent, error)

type WebSocketConnection

type WebSocketConnection struct {
	Resource        *WebSocketResource
	Protocol        string
	ResponseHeaders []Header
}

func OpenWebSocket

func OpenWebSocket(ctx context.Context, request WebSocketOpen) (WebSocketConnection, error)

type WebSocketOpen

type WebSocketOpen struct {
	URL          string
	Headers      []Header
	Subprotocols []string
	Timeout      time.Duration
	Authorize    func(context.Context, *url.URL) error
}

type WebSocketResource

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

func (*WebSocketResource) Close

func (resource *WebSocketResource) Close() error

func (*WebSocketResource) FullDuplexResource

func (*WebSocketResource) FullDuplexResource()

func (*WebSocketResource) GracefulClose

func (resource *WebSocketResource) GracefulClose(code websocket.StatusCode, reason string) error

func (*WebSocketResource) Ping

func (resource *WebSocketResource) Ping(ctx context.Context) error

func (*WebSocketResource) ReadChunk

func (resource *WebSocketResource) ReadChunk(ctx context.Context, destination []byte) (int, uint32, error)

func (*WebSocketResource) WriteOwnedChunk

func (resource *WebSocketResource) WriteOwnedChunk(ctx context.Context, owner Owner, source []byte, flags uint32) (int, error)

Jump to

Keyboard shortcuts

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