runtime

package
v0.51.0 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: Apache-2.0 Imports: 71 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ManifestPath = "manifest.yaml"
	LocaleDir    = "locales"
)
View Source
const (
	MinRequestTTL      = 5 * time.Second
	MaxResponseTTL     = 1 * time.Hour
	HTTPTimeout        = 5 * time.Second
	MaxResponseDefault = 20 * 1024 * 1024 // 20MB
	MaxResponseEnv     = "PIXLET_HTTP_MAX_RESPONSE_MB"
	HTTPCachePrefix    = "httpcache"
	TTLHeader          = "X-Tidbyt-Cache-Seconds"
)
View Source
const DefaultExpirationSeconds = 60

Variables

View Source
var (
	ErrMinPixletVersionInvalid = errors.New("manifest minPixletVersion is not a valid version string")
	ErrMinPixletVersion        = errors.New("app requires a newer pixlet version")
)
View Source
var ErrStarSuffix = fmt.Errorf("script file must have suffix .star")
View Source
var Version = "dev"

Functions

func DetermineTTL

func DetermineTTL(req *http.Request, resp *http.Response, randSource *rand.Rand) time.Duration

DetermineTTL determines the TTL for a request based on the request and response. We first check request method / response status code to determine if we should actually cache the response. Then we check the headers passed in from starlark to see if the user configured a TTL. Finally, if the response is cachable but the developer didn't configure a TTL, we check the response to get a hint at what the TTL should be.

func ExtractRoots

func ExtractRoots(val starlark.Value) ([]render.Root, error)

ExtractRoots extracts render roots from a Starlark value. It expects the value to be either a single render root or a list of render roots.

It's used internally by RunWithConfig to extract the roots returned by the applet.

func InitCache

func InitCache(c Cache)

func InitHTTP

func InitHTTP(cache Cache)

func LoadCacheModule

func LoadCacheModule() (starlark.StringDict, error)

func LoadSecretModule

func LoadSecretModule() (starlark.StringDict, error)

Types

type Applet

type Applet struct {
	ID       string
	Manifest *manifest.Manifest
	Globals  map[string]starlark.StringDict
	MainFile string
	Root     *os.Root

	Schema *schema.Schema
	// contains filtered or unexported fields
}

func NewApplet

func NewApplet(ctx context.Context, id string, src []byte, opts ...AppletOption) (*Applet, error)

func NewAppletFromFS

func NewAppletFromFS(ctx context.Context, id string, fsys fs.FS, opts ...AppletOption) (*Applet, error)

func NewAppletFromPath

func NewAppletFromPath(ctx context.Context, path string, opts ...AppletOption) (*Applet, error)

func NewAppletFromRoot added in v0.48.0

func NewAppletFromRoot(ctx context.Context, id string, root *os.Root, opts ...AppletOption) (*Applet, error)

func (*Applet) Call

func (a *Applet) Call(ctx context.Context, callable *starlark.Function, args ...starlark.Value) (val starlark.Value, err error)

Call calls any callable from Applet.Globals. Pass args and receive a starlark Value, or an error if you're unlucky.

func (*Applet) CallSchemaHandler

func (app *Applet) CallSchemaHandler(ctx context.Context, handlerName, parameter string, config map[string]any) (result string, err error)

CallSchemaHandler calls a schema handler, passing it a single string parameter and returning a single string value.

func (*Applet) Close added in v0.48.0

func (a *Applet) Close() error

func (*Applet) PathsForBundle

func (a *Applet) PathsForBundle() []string

PathsForBundle returns a list of all the paths that have been loaded by the applet. This is useful for creating a bundle of the applet.

func (*Applet) Run

func (a *Applet) Run(ctx context.Context) (roots []render.Root, err error)

Run executes the applet's main function. It returns the render roots that are returned by the applet.

func (*Applet) RunTests

func (app *Applet) RunTests(t *testing.T)

RunTests runs all test functions that are defined in the applet source.

func (*Applet) RunWithConfig

func (a *Applet) RunWithConfig(ctx context.Context, config map[string]any) (roots []render.Root, err error)

RunWithConfig exceutes the applet's main function, passing it configuration as a starlark dict. It returns the render roots that are returned by the applet.

type AppletConfig

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

func NewAppletConfig added in v0.50.0

func NewAppletConfig(config map[string]any, sch *schema.Schema) AppletConfig

func (AppletConfig) Attr

func (a AppletConfig) Attr(name string) (starlark.Value, error)

func (AppletConfig) AttrNames

func (a AppletConfig) AttrNames() []string

func (AppletConfig) Freeze

func (a AppletConfig) Freeze()

func (AppletConfig) Get

func (AppletConfig) Hash

func (a AppletConfig) Hash() (uint32, error)

func (AppletConfig) String

func (a AppletConfig) String() string

func (AppletConfig) Truth

func (a AppletConfig) Truth() starlark.Bool

func (AppletConfig) Type

func (a AppletConfig) Type() string

type AppletOption

type AppletOption func(*Applet) error

func WithCanvasMeta added in v0.49.0

func WithCanvasMeta(m canvas.Metadata) AppletOption

func WithLanguage added in v0.49.0

func WithLanguage(lang language.Tag) AppletOption

func WithLocation added in v0.49.0

func WithLocation(tz *time.Location) AppletOption

func WithModuleLoader

func WithModuleLoader(loader ModuleLoader) AppletOption

func WithPrintDisabled

func WithPrintDisabled() AppletOption

func WithPrintFunc

func WithPrintFunc(printFunc PrintFunc) AppletOption

func WithSecretDecryptionKey

func WithSecretDecryptionKey(key *SecretDecryptionKey) AppletOption

func WithTests added in v0.49.0

func WithTests(t testing.TB) AppletOption

func WithThreadInitializer

func WithThreadInitializer(init ThreadInitializer) AppletOption

type Cache

type Cache interface {
	Set(ctx context.Context, key string, value []byte, ttl int64) error
	Get(ctx context.Context, key string) ([]byte, bool, error)
	Close()
}

type InMemoryCache

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

func NewInMemoryCache

func NewInMemoryCache() *InMemoryCache

func (*InMemoryCache) Close added in v0.51.0

func (c *InMemoryCache) Close()

func (*InMemoryCache) Get

func (c *InMemoryCache) Get(_ context.Context, key string) (value []byte, found bool, err error)

func (*InMemoryCache) Set

func (c *InMemoryCache) Set(_ context.Context, key string, value []byte, ttl int64) error

type ModuleLoader

type ModuleLoader func(*starlark.Thread, string) (starlark.StringDict, error)

type PrintFunc

type PrintFunc func(thread *starlark.Thread, msg string)

type RedisCache

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

func NewRedisCache

func NewRedisCache(url string) *RedisCache

func (*RedisCache) Close added in v0.51.0

func (c *RedisCache) Close()

func (*RedisCache) Get

func (c *RedisCache) Get(ctx context.Context, key string) (value []byte, found bool, err error)

func (*RedisCache) Set

func (c *RedisCache) Set(ctx context.Context, key string, value []byte, ttl int64) error

type SecretDecryptionKey

type SecretDecryptionKey struct {
	// EncryptedKeysetJSON is the encrypted JSON representation of a Tink keyset.
	EncryptedKeysetJSON []byte

	// KeyEncryptionKey is a Tink key that can be used to decrypt the keyset.
	KeyEncryptionKey tink.AEAD
}

SecretDecryptionKey is a key that can be used to decrypt secrets.

type SecretEncryptionKey

type SecretEncryptionKey struct {
	// PublicKeysetJSON is the serialized JSON representation of a Tink keyset.
	PublicKeysetJSON []byte
}

SecretEncryptionKey is a key that can be used to encrypt secrets, but not decrypt them.

func (*SecretEncryptionKey) Encrypt

func (sek *SecretEncryptionKey) Encrypt(appID, plaintext string) (string, error)

Encrypt encrypts a value for use as a secret in an app. Provide both a value and the ID of the app the encrypted secret will be used in. The value will only be usable with the specified app.

type ThreadInitializer

type ThreadInitializer func(thread *starlark.Thread) *starlark.Thread

ThreadInitializer is called when building a Starlark thread to run an applet on. It can customize the thread by overriding behavior or attaching thread local data.

Jump to

Keyboard shortcuts

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