runtime

package
v0.32.7 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: Apache-2.0 Imports: 54 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MinRequestTTL    = 5 * time.Second
	MaxResponseTTL   = 1 * time.Hour
	HTTPTimeout      = 5 * time.Second
	MaxResponseBytes = 20 * 1024 * 1024 // 20MB
	HTTPCachePrefix  = "httpcache"
	TTLHeader        = "X-Tidbyt-Cache-Seconds"
)
View Source
const DefaultExpirationSeconds = 60

Variables

This section is empty.

Functions

func DetermineTTL added in v0.26.0

func DetermineTTL(req *http.Request, resp *http.Response) 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 InitCache

func InitCache(c Cache)

func InitHTTP added in v0.26.0

func InitHTTP(cache Cache)

func LoadCacheModule

func LoadCacheModule() (starlark.StringDict, error)

func LoadSecretModule added in v0.13.2

func LoadSecretModule() (starlark.StringDict, error)

Types

type Applet

type Applet struct {
	ID string

	Schema     *schema.Schema
	SchemaJSON []byte
	// contains filtered or unexported fields
}

func NewApplet added in v0.31.0

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

func NewAppletFromFS added in v0.32.0

func NewAppletFromFS(id string, fsys fs.FS, 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)

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

func (*Applet) CallSchemaHandler added in v0.10.0

func (app *Applet) CallSchemaHandler(ctx context.Context, handlerName, parameter string) (result string, err error)

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

func (*Applet) PathsForBundle added in v0.32.0

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 added in v0.31.0

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

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

func (*Applet) RunWithConfig added in v0.31.0

func (a *Applet) RunWithConfig(ctx context.Context, config map[string]string) (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 added in v0.12.0

type AppletConfig map[string]string

func (AppletConfig) Attr added in v0.12.0

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

func (AppletConfig) AttrNames added in v0.12.0

func (a AppletConfig) AttrNames() []string

func (AppletConfig) Freeze added in v0.12.0

func (a AppletConfig) Freeze()

func (AppletConfig) Get added in v0.12.0

func (AppletConfig) Hash added in v0.12.0

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

func (AppletConfig) String added in v0.12.0

func (a AppletConfig) String() string

func (AppletConfig) Truth added in v0.12.0

func (a AppletConfig) Truth() starlark.Bool

func (AppletConfig) Type added in v0.12.0

func (a AppletConfig) Type() string

type AppletOption added in v0.31.0

type AppletOption func(*Applet) error

func WithModuleLoader added in v0.31.0

func WithModuleLoader(loader ModuleLoader) AppletOption

func WithPrintDisabled added in v0.31.0

func WithPrintDisabled() AppletOption

func WithPrintFunc added in v0.31.0

func WithPrintFunc(print PrintFunc) AppletOption

func WithSecretDecryptionKey added in v0.31.0

func WithSecretDecryptionKey(key *SecretDecryptionKey) AppletOption

type Cache

type Cache interface {
	Set(thread *starlark.Thread, key string, value []byte, ttl int64) error
	Get(thread *starlark.Thread, key string) ([]byte, bool, error)
}

type InMemoryCache

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

func NewInMemoryCache

func NewInMemoryCache() *InMemoryCache

func (*InMemoryCache) Get

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

func (*InMemoryCache) Set

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

type InMemoryCacheRecord

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

type ModuleLoader

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

type PrintFunc added in v0.31.0

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

type SecretDecryptionKey added in v0.13.0

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 added in v0.13.0

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 added in v0.13.0

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 added in v0.5.1

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.

Directories

Path Synopsis
modules

Jump to

Keyboard shortcuts

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