provider

package module
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: May 5, 2025 License: Apache-2.0 Imports: 32 Imported by: 10

README

wasmCloud Provider SDK

Providers are swappable wasmCloud host plugins. They are executables (usually dedicated to longer-lived processes) that deliver common functionalities called capabilities. Providers are typically responsible for capabilities that are not considered part of the core business logic of an application, such as...

  • Sending notifications
  • Fetching secret values
  • Accessing databases
  • Serving content over HTTP

This package is an SDK for creating capability providers in Golang. You can implement a capability that's already defined, or create a custom capability interface and use that in your wasmCloud application.

Usage

An example can be found in examples/keyvalue-inmemory which implements the interface wrpc:keyvalue/store@0.2.0-draft.

Refer to the custom template for a comprehensive example of a custom provider.

Documentation

Index

Constants

View Source
const (
	OtelMetricExportInterval       = 1 * time.Minute
	OtelTraceExportInterval        = 1 * time.Minute
	OtelLogExportInterval          = 10 * time.Second
	OtelProtocolHTTP               = "http"
	OtelProtocolGRPC               = "grpc"
	OtelSpanLimitAttributePerEvent = 16
	OtelSpanLimitEventCount        = 64
)

Variables

This section is empty.

Functions

func DecryptSecrets

func DecryptSecrets(encryptedBytes *[]byte, xkey nkeys.KeyPair, sender string) (map[string]SecretValue, error)

Types

type HealthCheckResponse

type HealthCheckResponse struct {
	Healthy bool   `json:"healthy"`
	Message string `json:"message,omitempty"`
}

type HostData

type HostData struct {
	HostID                 string                     `json:"host_id,omitempty"`
	LatticeRPCPrefix       string                     `json:"lattice_rpc_prefix,omitempty"`
	LatticeRPCUserJWT      string                     `json:"lattice_rpc_user_jwt,omitempty"`
	LatticeRPCUserSeed     string                     `json:"lattice_rpc_user_seed,omitempty"`
	LatticeRPCURL          string                     `json:"lattice_rpc_url,omitempty"`
	ProviderKey            string                     `json:"provider_key,omitempty"`
	EnvValues              map[string]string          `json:"env_values,omitempty"`
	InstanceID             string                     `json:"instance_id,omitempty"`
	LinkDefinitions        []linkWithEncryptedSecrets `json:"link_definitions,omitempty"`
	ClusterIssuers         []string                   `json:"cluster_issuers,omitempty"`
	Config                 map[string]string          `json:"config,omitempty"`
	Secrets                map[string]SecretValue     `json:"secrets,omitempty"`
	HostXKeyPublicKey      string                     `json:"host_xkey_public_key,omitempty"`
	ProviderXKeyPrivateKey RedactedString             `json:"provider_xkey_private_key,omitempty"`
	DefaultRPCTimeoutMS    *uint64                    `json:"default_rpc_timeout_ms,omitempty"`
	StructuredLogging      bool                       `json:"structured_logging,omitempty"`
	LogLevel               *Level                     `json:"log_level,omitempty"`
	OtelConfig             OtelConfig                 `json:"otel_config,omitempty"`
}

type InterfaceLinkDefinition

type InterfaceLinkDefinition struct {
	SourceID      string                 `json:"source_id,omitempty"`
	Target        string                 `json:"target,omitempty"`
	Name          string                 `json:"name,omitempty"`
	WitNamespace  string                 `json:"wit_namespace,omitempty"`
	WitPackage    string                 `json:"wit_package,omitempty"`
	Interfaces    []string               `json:"interfaces,omitempty"`
	SourceConfig  map[string]string      `json:"source_config,omitempty"`
	TargetConfig  map[string]string      `json:"target_config,omitempty"`
	SourceSecrets map[string]SecretValue `json:"source_secrets,omitempty"`
	TargetSecrets map[string]SecretValue `json:"target_secrets,omitempty"`
}

type Level

type Level string
const (
	Error    Level = "error"
	Warn     Level = "warn"
	Info     Level = "info"
	Debug    Level = "debug"
	Trace    Level = "trace"
	Critical Level = "critical"
)

func (Level) Level

func (l Level) Level() slog.Level

func (Level) String

func (l Level) String() string

func (*Level) UnmarshalJSON

func (l *Level) UnmarshalJSON(data []byte) error

type OtelConfig

type OtelConfig struct {
	EnableObservability   bool   `json:"enable_observability"`
	EnableTraces          bool   `json:"enable_traces,omitempty"`
	EnableMetrics         bool   `json:"enable_metrics,omitempty"`
	EnableLogs            bool   `json:"enable_logs,omitempty"`
	ObservabilityEndpoint string `json:"observability_endpoint,omitempty"`
	TracesEndpoint        string `json:"traces_endpoint,omitempty"`
	MetricsEndpoint       string `json:"metrics_endpoint,omitempty"`
	LogsEndpoint          string `json:"logs_endpoint,omitempty"`
	Protocol              string `json:"protocol,omitempty"`
}

func (*OtelConfig) LogsEnabled added in v0.0.4

func (config *OtelConfig) LogsEnabled() bool

LogsEnabled returns whether emitting logs has been enabled.

func (*OtelConfig) LogsURL added in v0.0.4

func (config *OtelConfig) LogsURL() string

LogsURL returns the configured LogsEndpoint as-is if one is provided, otherwise it resolves the URL based on ObservabilityEndpoint value and the Protocol appropriate path.

func (*OtelConfig) MetricsEnabled added in v0.0.4

func (config *OtelConfig) MetricsEnabled() bool

MetricsEnabled returns whether emitting metrics has been enabled.

func (*OtelConfig) MetricsURL added in v0.0.4

func (config *OtelConfig) MetricsURL() string

MetricsURL returns the configured MetricsEndpoint as-is if one is provided, otherwise it resolves the URL based on ObservabilityEndpoint value and the Protocol appropriate path.

func (*OtelConfig) OtelProtocol added in v0.0.4

func (config *OtelConfig) OtelProtocol() string

OtelProtocol returns the configured OpenTelemetry protocol if one is provided, otherwise defaulting to http.

func (*OtelConfig) TracesEnabled added in v0.0.4

func (config *OtelConfig) TracesEnabled() bool

TracesEnabled returns whether emitting traces has been enabled.

func (*OtelConfig) TracesURL added in v0.0.4

func (config *OtelConfig) TracesURL() string

TracesURL returns the configured TracesEndpoint as-is if one is provided, otherwise it resolves the URL based on ObservabilityEndpoint value and the Protocol appropriate path.

type ProviderHandler

type ProviderHandler func(*WasmcloudProvider) error

func HealthCheck

func HealthCheck(inFunc func() string) ProviderHandler

func Shutdown

func Shutdown(inFunc func() error) ProviderHandler

func SourceLinkDel

func SourceLinkDel(inFunc func(InterfaceLinkDefinition) error) ProviderHandler

func SourceLinkPut

func SourceLinkPut(inFunc func(InterfaceLinkDefinition) error) ProviderHandler

func TargetLinkDel

func TargetLinkDel(inFunc func(InterfaceLinkDefinition) error) ProviderHandler

func TargetLinkPut

func TargetLinkPut(inFunc func(InterfaceLinkDefinition) error) ProviderHandler

type RedactedString added in v0.0.3

type RedactedString string

func (RedactedString) MarshalJSON added in v0.0.3

func (rs RedactedString) MarshalJSON() ([]byte, error)

func (RedactedString) Reveal added in v0.0.3

func (rs RedactedString) Reveal() string

func (RedactedString) String added in v0.0.3

func (rs RedactedString) String() string

type SecretBytesValue

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

func (SecretBytesValue) Reveal

func (s SecretBytesValue) Reveal() []byte

func (SecretBytesValue) String

func (s SecretBytesValue) String() string

type SecretStringValue

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

func (SecretStringValue) Reveal

func (s SecretStringValue) Reveal() string

func (SecretStringValue) String

func (s SecretStringValue) String() string

func (*SecretStringValue) UnmarshalJSON

func (s *SecretStringValue) UnmarshalJSON(data []byte) error

type SecretValue

type SecretValue struct {
	String SecretStringValue
	Bytes  SecretBytesValue
}

func (*SecretValue) UnmarshalJSON

func (s *SecretValue) UnmarshalJSON(data []byte) error

Secret values are serialized as either a String or Bytes value, e.g. {"kind": "String", "value": "my secret"} or {"kind": "Bytes", "value": [1, 2, 3]}

type Topics

type Topics struct {
	LatticeLinkGet  string
	LatticeLinkDel  string
	LatticeLinkPut  string
	LatticeHealth   string
	LatticeShutdown string
}

func LatticeTopics

func LatticeTopics(h HostData, providerXkey nkeys.KeyPair) Topics

type WasmcloudProvider

type WasmcloudProvider struct {
	ID string

	Logger *slog.Logger

	Topics Topics

	RPCClient *wrpcnats.Client
	// contains filtered or unexported fields
}

func New

func New(options ...ProviderHandler) (*WasmcloudProvider, error)

func NewWithHostDataSource added in v0.0.3

func NewWithHostDataSource(source io.Reader, options ...ProviderHandler) (*WasmcloudProvider, error)

func (*WasmcloudProvider) DecryptLinkSecrets

func (wp *WasmcloudProvider) DecryptLinkSecrets(h linkWithEncryptedSecrets) (InterfaceLinkDefinition, error)

func (*WasmcloudProvider) HostData

func (wp *WasmcloudProvider) HostData() HostData

func (*WasmcloudProvider) NatsConnection

func (wp *WasmcloudProvider) NatsConnection() *nats.Conn

func (*WasmcloudProvider) OutgoingRpcClient

func (wp *WasmcloudProvider) OutgoingRpcClient(target string) *wrpcnats.Client

func (*WasmcloudProvider) Shutdown

func (wp *WasmcloudProvider) Shutdown() error

func (*WasmcloudProvider) Start

func (wp *WasmcloudProvider) Start() error

Directories

Path Synopsis
Generated by `wit-bindgen-wrpc-go` 0.9.1.
Generated by `wit-bindgen-wrpc-go` 0.9.1.
wasi/clocks/monotonic_clock
Generated by `wit-bindgen-wrpc-go` 0.9.1.
Generated by `wit-bindgen-wrpc-go` 0.9.1.
wasi/http/types
Generated by `wit-bindgen-wrpc-go` 0.9.1.
Generated by `wit-bindgen-wrpc-go` 0.9.1.
wasi/io/error
Generated by `wit-bindgen-wrpc-go` 0.9.1.
Generated by `wit-bindgen-wrpc-go` 0.9.1.
wasi/io/poll
Generated by `wit-bindgen-wrpc-go` 0.9.1.
Generated by `wit-bindgen-wrpc-go` 0.9.1.
wasi/io/streams
Generated by `wit-bindgen-wrpc-go` 0.9.1.
Generated by `wit-bindgen-wrpc-go` 0.9.1.
wrpc/http/incoming_handler
Generated by `wit-bindgen-wrpc-go` 0.9.1.
Generated by `wit-bindgen-wrpc-go` 0.9.1.
wrpc/http/types
Generated by `wit-bindgen-wrpc-go` 0.9.1.
Generated by `wit-bindgen-wrpc-go` 0.9.1.

Jump to

Keyboard shortcuts

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