Documentation
¶
Index ¶
- Constants
- Variables
- func DetermineTTL(req *http.Request, resp *http.Response, randSource *rand.Rand) time.Duration
- func ExtractRoots(val starlark.Value) ([]render.Root, error)
- func InitCache(c Cache)
- func InitHTTP(cache Cache)
- func LoadCacheModule() (starlark.StringDict, error)
- func LoadSecretModule() (starlark.StringDict, error)
- type Applet
- func NewApplet(ctx context.Context, id string, src []byte, opts ...AppletOption) (*Applet, error)
- func NewAppletFromFS(ctx context.Context, id string, fsys fs.FS, opts ...AppletOption) (*Applet, error)
- func NewAppletFromPath(ctx context.Context, path string, opts ...AppletOption) (*Applet, error)
- func NewAppletFromRoot(ctx context.Context, id string, root *os.Root, opts ...AppletOption) (*Applet, error)
- func (a *Applet) Call(ctx context.Context, callable *starlark.Function, args ...starlark.Value) (val starlark.Value, err error)
- func (app *Applet) CallSchemaHandler(ctx context.Context, handlerName, parameter string, config map[string]any) (result string, err error)
- func (a *Applet) Close() error
- func (a *Applet) PathsForBundle() []string
- func (a *Applet) Run(ctx context.Context) (roots []render.Root, err error)
- func (app *Applet) RunTests(t *testing.T)
- func (a *Applet) RunWithConfig(ctx context.Context, config map[string]any) (roots []render.Root, err error)
- type AppletConfig
- func (a AppletConfig) Attr(name string) (starlark.Value, error)
- func (a AppletConfig) AttrNames() []string
- func (a AppletConfig) Freeze()
- func (a AppletConfig) Get(key starlark.Value) (starlark.Value, bool, error)
- func (a AppletConfig) Hash() (uint32, error)
- func (a AppletConfig) String() string
- func (a AppletConfig) Truth() starlark.Bool
- func (a AppletConfig) Type() string
- type AppletOption
- func WithCanvasMeta(m canvas.Metadata) AppletOption
- func WithLanguage(lang language.Tag) AppletOption
- func WithLocation(tz *time.Location) AppletOption
- func WithModuleLoader(loader ModuleLoader) AppletOption
- func WithPrintDisabled() AppletOption
- func WithPrintFunc(printFunc PrintFunc) AppletOption
- func WithSecretDecryptionKey(key *SecretDecryptionKey) AppletOption
- func WithTests(t testing.TB) AppletOption
- func WithThreadInitializer(init ThreadInitializer) AppletOption
- type Cache
- type InMemoryCache
- type ModuleLoader
- type PrintFunc
- type RedisCache
- type SecretDecryptionKey
- type SecretEncryptionKey
- type ThreadInitializer
Constants ¶
const ( ManifestPath = "manifest.yaml" LocaleDir = "locales" )
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" )
const DefaultExpirationSeconds = 60
Variables ¶
var ( ErrMinPixletVersionInvalid = errors.New("manifest minPixletVersion is not a valid version string") ErrMinPixletVersion = errors.New("app requires a newer pixlet version") )
var ErrStarSuffix = fmt.Errorf("script file must have suffix .star")
var Version = "dev"
Functions ¶
func DetermineTTL ¶
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 ¶
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 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 NewAppletFromFS ¶
func NewAppletFromPath ¶
func NewAppletFromRoot ¶ added in v0.48.0
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) PathsForBundle ¶
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 ¶
Run executes the applet's main function. 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) AttrNames ¶
func (a AppletConfig) AttrNames() []string
func (AppletConfig) Freeze ¶
func (a AppletConfig) Freeze()
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 ¶
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 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()
type ModuleLoader ¶
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()
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.