wape

package module
v0.0.0-...-6b19f5b Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2025 License: MIT Imports: 15 Imported by: 2 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README ΒΆ

πŸ‘Ύ WAPE

WAPE (WebAssembly Plugin Engine) is a wrapper for creating/running Extism plugins (or just programs) which is based on Wazero zero dependency WASM runtime for Go.

The main goal of this project is to provide a simple way to create and run WASM modules with very flexible policy based access to host resources with additional host functions for different use-cases.

πŸ” License

WASM Gate is distributed under MIT licence.

Documentation ΒΆ

Index ΒΆ

Constants ΒΆ

This section is empty.

Variables ΒΆ

This section is empty.

Functions ΒΆ

func NewCompiledPlugin ΒΆ

func NewCompiledPlugin(ctx context.Context, env *Environment) (*extism.CompiledPlugin, error)

NewCompiledPlugin creates a new compiled Extism plugin.

func NewPlugin ΒΆ

func NewPlugin(ctx context.Context, env *Environment) (*extism.Plugin, error)

NewPlugin creates a new Extism plugin.

Types ΒΆ

type Environment ΒΆ

type Environment struct {

	// Envs sets an environment variables.
	Envs []string `json:"envs,omitempty" yaml:"envs,omitempty" toml:"envs,omitempty"`
	// EnvsMap sets an environment variables as a map.
	EnvsMap map[string]string `json:"envsMap,omitempty" yaml:"envsMap,omitempty" toml:"envsMap,omitempty"`
	// EnvsFile sets an environment variables from a file.
	EnvsFile string `json:"envsFile,omitempty" yaml:"envsFile,omitempty" toml:"envsFile,omitempty"`
	// EnvsFromHost pass thought environment variables from the host.
	EnvsFromHost bool `json:"envsFromHost,omitempty" yaml:"envsFromHost,omitempty" toml:"envsFromHost,omitempty"`

	// Args assigns command-line arguments.
	Args []string `json:"args,omitempty" yaml:"args,omitempty" toml:"args,omitempty"`
	// ArgsFile assigns command-line arguments from a file.
	ArgsFile string `json:"argsFile,omitempty" yaml:"argsFile,omitempty" toml:"argsFile,omitempty"`
	// ArgsFromHost pass thought command-line arguments from the host.
	ArgsFromHost bool `json:"argsFromHost,omitempty" yaml:"argsFromHost,omitempty" toml:"argsFromHost,omitempty"`

	// Stdin configures where standard input (file descriptor 0) is read.
	Stdin io.Reader `json:"-" yaml:"-" toml:"-"`
	// StdinFile configures standard input (file descriptor 0) to read from a file.
	StdinFile string `json:"stdinFile,omitempty" yaml:"stdinFile,omitempty" toml:"stdinFile,omitempty"`
	// StdinFromHost pass thought stdin from the host.
	StdinFromHost bool `json:"stdinFromHost,omitempty" yaml:"stdinFromHost,omitempty" toml:"stdinFromHost,omitempty"`

	// Stdout configures where standard output (file descriptor 1) is written.
	Stdout io.Writer `json:"-" yaml:"-" toml:"-"`
	// StdoutFile configures standard output (file descriptor 1) to write to a file.
	StdoutFile string `json:"stdoutFile,omitempty" yaml:"stdoutFile,omitempty" toml:"stdoutFile,omitempty"`
	// StdoutFromHost pass thought stdout from the host.
	StdoutFromHost bool `json:"stdoutFromHost,omitempty" yaml:"stdoutFromHost,omitempty" toml:"stdoutFromHost,omitempty"`

	// Stderr configures where standard error (file descriptor 2) is written.
	Stderr io.Writer `json:"-" yaml:"-" toml:"-"`
	// StderrFile configures standard error (file descriptor 2) to write to a file.
	StderrFile string `json:"stderrFile,omitempty" yaml:"stderrFile,omitempty" toml:"stderrFile,omitempty"`
	// StderrFromHost pass thought stderr from the host.
	StderrFromHost bool `json:"stderrFromHost,omitempty" yaml:"stderrFromHost,omitempty" toml:"stderrFromHost,omitempty"`

	// FS configures the filesystem.
	FS fs.FS `json:"-" yaml:"-" toml:"-"`
	// FSFile configures the filesystem mount points.
	FSConfig wazero.FSConfig `json:"-" yaml:"-" toml:"-"`
	// FSDir configures the filesystem as a root directory.
	FSDir string `json:"fsDir,omitempty" yaml:"fsDir,omitempty" toml:"fsDir,omitempty"`
	// FSAllowedPaths configures the allowed filesystem paths that will be mapped in WASM module.
	// Host paths prefixed with "ro:" are marked as read-only.
	FSAllowedPaths map[string]string `json:"fsAllowedPaths,omitempty" yaml:"fsAllowedPaths,omitempty" toml:"fsAllowedPaths,omitempty"`
	// FSFromHost pass thought filesystem from the host.
	FSFromHost bool `json:"fsFromHost,omitempty" yaml:"fsFromHost,omitempty" toml:"fsFromHost,omitempty"`

	// RandSource configures a source of random bytes.
	RandSource io.Reader `json:"-" yaml:"-" toml:"-"`
	// RandSourceFile configures a source of random bytes from a file.
	RandSourceFile string `json:"randSourceFile,omitempty" yaml:"randSourceFile,omitempty" toml:"randSourceFile,omitempty"`
	// RandSourceFromHost pass thought random source from the host.
	RandSourceFromHost bool `json:"randSourceFromHost,omitempty" yaml:"randSourceFromHost,omitempty" toml:"randSourceFromHost,omitempty"`

	// WallTime returns the current unix/epoch time, seconds since midnight UTC 1 January 1970,
	// with a nanosecond fraction.
	WallTime sys.Walltime `json:"-" yaml:"-" toml:"-"`
	// WallTimeClockResolution configures the resolution of the wall clock, defaults to 1ns.
	WallTimeClockResolution sys.ClockResolution `json:"-" yaml:"-" toml:"-"`
	// WallTimeFromHost pass thought wall time from the host.
	WallTimeFromHost bool `json:"wallTimeFromHost,omitempty" yaml:"wallTimeFromHost,omitempty" toml:"wallTimeFromHost,omitempty"`

	// NanoTime returns nanoseconds since an arbitrary start point, used to measure elapsed time.
	// This is sometimes referred to as a tick or monotonic time.
	NanoTime sys.Nanotime `json:"-" yaml:"-" toml:"-"`
	// NanoTimeClockResolution configures the resolution of the nano clock, defaults to 1ns.
	NanoTimeClockResolution sys.ClockResolution `json:"-" yaml:"-" toml:"-"`
	// NanoTimeFromHost pass thought nano time from the host.
	NanoTimeFromHost bool `json:"nanoTimeFromHost,omitempty" yaml:"nanoTimeFromHost,omitempty" toml:"nanoTimeFromHost,omitempty"`

	// NanoSleep puts the current goroutine to sleep for at least ns nanoseconds.
	NanoSleep sys.Nanosleep `json:"-" yaml:"-" toml:"-"`
	// NanoSleepFromHost pass thought nano sleep from the host.
	NanoSleepFromHost bool `json:"nanoSleepFromHost,omitempty" yaml:"nanoSleepFromHost,omitempty" toml:"nanoSleepFromHost,omitempty"`

	// StartFunctions configures the functions to call after the module is instantiated.
	StartFunctions []string `json:"startFunctions,omitempty" yaml:"startFunctions,omitempty" toml:"startFunctions,omitempty"`

	// MemoryLimitPages overrides the maximum pages allowed per memory. Defaults to 65536, allowing 4GB total memory
	// per instance if the maximum is not encoded in a WASM binary. Max is 65536 (2^16) pages or 4GB.
	MemoryLimitPages uint32 `json:"memoryLimitPages,omitempty" yaml:"memoryLimitPages,omitempty" toml:"memoryLimitPages,omitempty"`

	// MemoryCapacityFromMax eagerly allocates max memory. Defaults to false, which means minimum memory is
	// allocated and any call to grow memory results in re-allocations.
	MemoryCapacityFromMax bool `json:"memoryCapacityFromMax,omitempty" yaml:"memoryCapacityFromMax,omitempty" toml:"memoryCapacityFromMax,omitempty"`

	// MaxExecutionDuration limits the maximum function execution time.
	// Rounded to milliseconds and has a minimum of 1ms. Defaults to 0 (no limit).
	MaxExecutionDuration time.Duration `json:"maxExecutionDuration,omitempty" yaml:"maxExecutionDuration,omitempty" toml:"maxExecutionDuration,omitempty"`

	// DebugInfoEnabled toggles DWARF-based stack traces in the face of runtime errors. Defaults to false.
	DebugInfoEnabled bool `json:"debugInfoEnabled,omitempty" yaml:"debugInfoEnabled,omitempty" toml:"debugInfoEnabled,omitempty"`

	// ExtismDebugEnvAllowed allows use of EXTISM_ENABLE_WASI_OUTPUT environment variable. Defaults to false (unsets
	// this variable, so it will not work for all WASM modules).
	ExtismDebugEnvAllowed bool `json:"extismDebugEnvAllowed,omitempty" yaml:"extismDebugEnvAllowed,omitempty" toml:"extismDebugEnvAllowed,omitempty"`

	// NetworkEnabled toggles network access. Defaults to false.
	NetworkEnabled bool `json:"networkEnabled,omitempty" yaml:"networkEnabled,omitempty" toml:"networkEnabled,omitempty"`

	// NetworkFilter allows to create custom filtering for networks and addresses.
	// Takes priority over networks and addresses configurations if present. Defaults to nil.
	NetworkFilter func(ctx context.Context, network, address string) (bool, error) `json:"-" yaml:"-" toml:"-"`

	// NetworksAllowed configures the allowed network protocols. See [net.Dial] for allowed protocols. Defaults to none.
	NetworksAllowed []string `json:"networksAllowed,omitempty" yaml:"networksAllowed,omitempty" toml:"networksAllowed,omitempty"`
	// NetworksAllowAll allows all network protocols. Defaults to false.
	NetworksAllowAll bool `json:"networksAllowAll,omitempty" yaml:"networksAllowAll,omitempty" toml:"networksAllowAll,omitempty"`

	// NetworkAddressesAllowed configures the allowed network addresses. Defaults to none.
	NetworkAddressesAllowed []string `json:"networkAddressesAllowed,omitempty" yaml:"networkAddressesAllowed,omitempty" toml:"networkAddressesAllowed,omitempty"`
	// NetworkAddressesAllowAll allows all network addresses. Defaults to false.
	NetworkAddressesAllowAll bool `json:"networkAddressesAllowAll,omitempty" yaml:"networkAddressesAllowAll,omitempty" toml:"networkAddressesAllowAll,omitempty"`

	// DisableWASI disables WASI Preview 1 support. Defaults to false.
	DisableWASI bool `json:"disableWASI,omitempty" yaml:"disableWASI,omitempty" toml:"disableWASI,omitempty"`

	// CompilationCache configures the compilation cache.
	CompilationCache wazero.CompilationCache `json:"-" yaml:"-" toml:"-"`
	// CompilationCacheDir configures the compilation cache directory.
	CompilationCacheDir string `json:"compilationCacheDir,omitempty" yaml:"compilationCacheDir,omitempty" toml:"compilationCacheDir,omitempty"`

	// CustomSectionsEnabled configures whether to enable custom sections.
	CustomSectionsEnabled bool `json:"customSectionsEnabled,omitempty" yaml:"customSectionsEnabled,omitempty" toml:"customSectionsEnabled,omitempty"`

	// ModuleConfig configures the WASM module.
	ModuleConfig wazero.ModuleConfig `json:"-" yaml:"-" toml:"-"`
	// RuntimeConfig configures the WASM runtime.
	RuntimeConfig wazero.RuntimeConfig `json:"-" yaml:"-" toml:"-"`

	// Manifest is the plugin manifest that can be provided instead of configuration above.
	Manifest *extism.Manifest `json:"manifest,omitempty" yaml:"manifest,omitempty" toml:"manifest,omitempty"`
	// PluginConfig is the plugin configuration that can be provided instead of configuration above.
	PluginConfig *extism.PluginConfig `json:"-" yaml:"-" toml:"-"`
	// PluginInstanceConfig is the plugin instance configuration that can be provided instead of configuration above.
	PluginInstanceConfig *extism.PluginInstanceConfig `json:"-" yaml:"-" toml:"-"`

	// HostFunctions host functions available to the guest WASM module.
	HostFunctions []extism.HostFunction `json:"-" yaml:"-" toml:"-"`

	// Modules configures the WASM modules.
	Modules []ModuleData `json:"modules,omitempty" yaml:"modules,omitempty" toml:"modules,omitempty"`
}

Environment configures the behavior of WASM module.

Note: Many environment configurations override each other, for example providing ModuleConfig will override all other configurations related to envs, args, FS, etc. Be aware that you may end up with unexpected behavior.

func NewEnvironment ΒΆ

func NewEnvironment() *Environment

NewEnvironment returns a new environment.

func (*Environment) MakeHostFunctions ΒΆ

func (e *Environment) MakeHostFunctions() []extism.HostFunction

MakeHostFunctions returns the host functions based on the environment.

func (*Environment) MakeManifest ΒΆ

func (e *Environment) MakeManifest() extism.Manifest

MakeManifest returns the manifest based on the environment.

func (*Environment) MakeModuleConfig ΒΆ

func (e *Environment) MakeModuleConfig() wazero.ModuleConfig

MakeModuleConfig returns the module configuration based on the environment.

func (*Environment) MakePluginConfig ΒΆ

func (e *Environment) MakePluginConfig() extism.PluginConfig

MakePluginConfig returns the plugin configuration based on the environment.

func (*Environment) MakePluginInstanceConfig ΒΆ

func (e *Environment) MakePluginInstanceConfig() extism.PluginInstanceConfig

MakePluginInstanceConfig returns the plugin instance configuration based on the environment.

func (*Environment) MakeRuntimeConfig ΒΆ

func (e *Environment) MakeRuntimeConfig() wazero.RuntimeConfig

MakeRuntimeConfig returns the runtime configuration based on the environment.

type ModuleData ΒΆ

type ModuleData struct {
	// Name of the WASM module.
	Name string `json:"name" yaml:"name" toml:"name"`

	// Source of WASM module.
	Data []byte `json:"data,omitempty" yaml:"data,omitempty" toml:"data,omitempty"`

	// File path to read WASM module.
	File string `json:"file,omitempty" yaml:"file,omitempty" toml:"file,omitempty"`

	// Url to download WASM module.
	Url string `json:"url,omitempty" yaml:"url,omitempty" toml:"url,omitempty"`
	// Method to download WASM module.
	// Defaults to "GET".
	HttpMethod string `json:"httpMethod,omitempty" yaml:"httpMethod,omitempty" toml:"httpMethod,omitempty"`
	// Headers to download WASM module.
	HttpHeaders map[string]string `json:"httpHeaders,omitempty" yaml:"httpHeaders,omitempty" toml:"httpHeaders,omitempty"`

	// SHA256 hash of WASM module to validate it.
	Hash string `json:"hash,omitempty" yaml:"hash,omitempty" toml:"hash,omitempty"`
}

ModuleData represents WASM module with name and data.

Directories ΒΆ

Path Synopsis
cmd
wape command
host
io
net
plugin module

Jump to

Keyboard shortcuts

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