Documentation
¶
Overview ¶
Package azurefunctions emulates Azure Functions and Linux App Service web apps. Function apps' HTTP-triggered functions run in the official Azure Functions host containers behind <app>.<domain>/api/<function>, with the host's own authLevel key enforcement; web apps run their stack or custom image behind <app>.<domain>. Both get the Kudu zip-deploy API on <app>.scm.<domain>. Apps are created through the ARM Microsoft.Web provider, which shares their settings, keys and packages. See PARITY.md.
Index ¶
- Constants
- Variables
- func ValidateConfig(cfg AppConfig) error
- type AppConfig
- type AppInfo
- type ConfigProvider
- type Deployment
- type FunctionDef
- type FunctionInfo
- type Handler
- func (h *Handler) ExtractOperation(*echo.Context) string
- func (h *Handler) ExtractResource(*echo.Context) string
- func (h *Handler) GetSupportedOperations() []string
- func (h *Handler) Handler() echo.HandlerFunc
- func (h *Handler) MatchPriority() int
- func (h *Handler) Name() string
- func (h *Handler) Reset()
- func (h *Handler) Restore(ctx context.Context, data []byte) error
- func (h *Handler) RouteMatcher() service.Matcher
- func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (h *Handler) Shutdown(ctx context.Context)
- func (h *Handler) Snapshot(ctx context.Context) []byte
- func (h *Handler) StartWorker(ctx context.Context) error
- type HostKeys
- type InMemoryBackend
- func (b *InMemoryBackend) App(name string) (AppInfo, bool)
- func (b *InMemoryBackend) Close()
- func (b *InMemoryBackend) Configure(s Settings)
- func (b *InMemoryBackend) DeleteApp(name string)
- func (b *InMemoryBackend) DeleteFunctionKey(name, fn, keyName string) error
- func (b *InMemoryBackend) DeleteHostKey(name, keyType, keyName string) error
- func (b *InMemoryBackend) Deploy(name string, zipData []byte, deployer, message string) (Deployment, error)
- func (b *InMemoryBackend) Deployments(name string) ([]Deployment, error)
- func (b *InMemoryBackend) Function(ctx context.Context, name, fn string) (FunctionInfo, error)
- func (b *InMemoryBackend) FunctionKeys(name, fn string) (map[string]string, error)
- func (b *InMemoryBackend) Functions(ctx context.Context, name string) ([]FunctionInfo, error)
- func (b *InMemoryBackend) HostKeys(name string) (HostKeys, error)
- func (b *InMemoryBackend) HostName(name string) string
- func (b *InMemoryBackend) Names() []string
- func (b *InMemoryBackend) Package(name string) []byte
- func (b *InMemoryBackend) PublishingCredentials(name string) (string, string, string, error)
- func (b *InMemoryBackend) PutApp(name string, cfg AppConfig) AppInfo
- func (b *InMemoryBackend) Reset()
- func (b *InMemoryBackend) Restart(name string) error
- func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error
- func (b *InMemoryBackend) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (b *InMemoryBackend) SetFunctionKey(name, fn, keyName, value string) (string, error)
- func (b *InMemoryBackend) SetHostKey(name, keyType, keyName, value string) (string, error)
- func (b *InMemoryBackend) SetOnClose(fn func())
- func (b *InMemoryBackend) SetPortPool(p PortPool)
- func (b *InMemoryBackend) SetRuntime(fn func() (Runner, error))
- func (b *InMemoryBackend) SetSettings(name string, settings map[string]string) error
- func (b *InMemoryBackend) SetStopped(name string, stopped bool) error
- func (b *InMemoryBackend) Settings(name string) (map[string]string, error)
- func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte
- type PortPool
- type Provider
- type Runner
- type Settings
Constants ¶
const ( // KeyTypeFunction and KeyTypeSystem are the host key collections ARM addresses as host/default/{keyType}. KeyTypeFunction = "functionKeys" // KeyTypeSystem is the host key collection extensions use. KeyTypeSystem = "systemKeys" )
const ( // DefaultPort is the function-app and Kudu listener's default TCP port. DefaultPort = 10012 // DefaultDomain is the default hostname suffix: <app>.<domain> serves functions, <app>.scm.<domain> Kudu. DefaultDomain = "azurewebsites.localhost" // EngineAuto runs function apps in the container runtime when one is reachable. EngineAuto = "auto" // EngineNone never starts containers: apps deploy but invocations return 503. EngineNone = "none" // DefaultStartupTimeout bounds how long a function host container may take to accept connections. DefaultStartupTimeout = 5 * time.Minute )
Variables ¶
var ( // ErrNilAppContext is returned when Init is called with a nil AppContext. ErrNilAppContext = errors.New("azurefunctions: nil app context") // ErrAppNotFound is returned for an unknown function app. ErrAppNotFound = errors.New("azurefunctions: function app not found") // ErrFunctionNotFound is returned for an unknown function. ErrFunctionNotFound = errors.New("azurefunctions: function not found") // ErrKeyNotFound is returned for an unknown host or function key. ErrKeyNotFound = errors.New("azurefunctions: key not found") // ErrInvalidKeyType is returned for a host key type other than functionKeys or systemKeys. ErrInvalidKeyType = errors.New("azurefunctions: key type must be functionKeys or systemKeys") // ErrInvalidPackage is returned when a deployment is not a readable zip archive. ErrInvalidPackage = errors.New("azurefunctions: deployment package is not a valid zip archive") )
Functions ¶
func ValidateConfig ¶
ValidateConfig reports whether the emulator can run the app's stack; function apps are validated at start.
Types ¶
type AppConfig ¶
AppConfig is what ARM supplies about a site: its kind and the runtime stack it selected.
type AppInfo ¶
type AppInfo struct {
Created time.Time
LastDeploy time.Time
HostName string
SCMHost string
Image string
Worker string
Failure string
Stopped bool
Deployed bool
}
AppInfo is the data plane's view of an app.
type ConfigProvider ¶
type ConfigProvider interface {
GetAzureFunctionsSettings() Settings
}
ConfigProvider extracts the Azure Functions settings from the AppContext config.
type Deployment ¶
type Deployment struct {
Received time.Time `json:"received"`
Finished time.Time `json:"finished"`
ID string `json:"id"`
Deployer string `json:"deployer"`
Message string `json:"message"`
Succeeded bool `json:"succeeded"`
}
Deployment is one Kudu deployment record.
type FunctionDef ¶
FunctionDef is one function discovered from a deployed package's function.json files.
type FunctionInfo ¶
type FunctionInfo struct {
Config map[string]any
Name string
Language string
InvokeURL string
IsDisabled bool
}
FunctionInfo describes one function of an app.
type Handler ¶
type Handler struct {
Backend *InMemoryBackend
Settings Settings
Port int
// contains filtered or unexported fields
}
Handler owns the function-app listener.
func NewHandler ¶
func NewHandler(backend *InMemoryBackend, settings Settings) *Handler
NewHandler returns a Handler over backend.
func (*Handler) ExtractOperation ¶
ExtractOperation implements service.Service.
func (*Handler) ExtractResource ¶
ExtractResource implements service.Service.
func (*Handler) GetSupportedOperations ¶
GetSupportedOperations implements service.Service.
func (*Handler) Handler ¶
func (h *Handler) Handler() echo.HandlerFunc
Handler returns a 404 handler; the real API is on the dedicated port.
func (*Handler) MatchPriority ¶
MatchPriority implements service.Registerable.
func (*Handler) RouteMatcher ¶
RouteMatcher never matches: function apps listen on their own port.
func (*Handler) ServeHTTP ¶
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP serves the dedicated listener.
type HostKeys ¶
type HostKeys struct {
FunctionKeys map[string]string
SystemKeys map[string]string
MasterKey string
}
HostKeys are an app's host-level keys.
type InMemoryBackend ¶
type InMemoryBackend struct {
// contains filtered or unexported fields
}
InMemoryBackend holds all function apps under one lock.
func NewInMemoryBackend ¶
func NewInMemoryBackend() *InMemoryBackend
NewInMemoryBackend creates an empty backend with no container runtime.
func (*InMemoryBackend) App ¶
func (b *InMemoryBackend) App(name string) (AppInfo, bool)
App returns the app's data-plane view.
func (*InMemoryBackend) Close ¶
func (b *InMemoryBackend) Close()
Close stops every host and runs the onClose hook.
func (*InMemoryBackend) Configure ¶
func (b *InMemoryBackend) Configure(s Settings)
Configure applies the listener-facing settings.
func (*InMemoryBackend) DeleteApp ¶
func (b *InMemoryBackend) DeleteApp(name string)
DeleteApp stops and removes the app.
func (*InMemoryBackend) DeleteFunctionKey ¶
func (b *InMemoryBackend) DeleteFunctionKey(name, fn, keyName string) error
DeleteFunctionKey removes a function key.
func (*InMemoryBackend) DeleteHostKey ¶
func (b *InMemoryBackend) DeleteHostKey(name, keyType, keyName string) error
DeleteHostKey removes a host key.
func (*InMemoryBackend) Deploy ¶
func (b *InMemoryBackend) Deploy(name string, zipData []byte, deployer, message string) (Deployment, error)
Deploy stores a zip package as the app's site content and records the deployment.
func (*InMemoryBackend) Deployments ¶
func (b *InMemoryBackend) Deployments(name string) ([]Deployment, error)
Deployments returns the app's deployments, newest last.
func (*InMemoryBackend) Function ¶
func (b *InMemoryBackend) Function(ctx context.Context, name, fn string) (FunctionInfo, error)
Function returns one function of the app.
func (*InMemoryBackend) FunctionKeys ¶
func (b *InMemoryBackend) FunctionKeys(name, fn string) (map[string]string, error)
FunctionKeys returns a function's keys, creating its default key on first use as Azure does.
func (*InMemoryBackend) Functions ¶
func (b *InMemoryBackend) Functions(ctx context.Context, name string) ([]FunctionInfo, error)
Functions lists the app's functions. With a container runtime they come from the running host's admin API, which also sees code-first (no function.json) functions; without one, from the deployed package's function.json files.
func (*InMemoryBackend) HostKeys ¶
func (b *InMemoryBackend) HostKeys(name string) (HostKeys, error)
HostKeys returns the app's master, function and system keys.
func (*InMemoryBackend) HostName ¶
func (b *InMemoryBackend) HostName(name string) string
HostName is the default hostname apps are served under, including the listener port.
func (*InMemoryBackend) Names ¶
func (b *InMemoryBackend) Names() []string
Names lists app names in order.
func (*InMemoryBackend) Package ¶
func (b *InMemoryBackend) Package(name string) []byte
Package returns the deployed zip, or nil.
func (*InMemoryBackend) PublishingCredentials ¶
PublishingCredentials returns the Kudu user name, password and base URL.
func (*InMemoryBackend) PutApp ¶
func (b *InMemoryBackend) PutApp(name string, cfg AppConfig) AppInfo
PutApp creates the app or updates its kind and stack, keeping settings, keys and package.
func (*InMemoryBackend) Reset ¶
func (b *InMemoryBackend) Reset()
Reset stops every host and clears all apps.
func (*InMemoryBackend) Restart ¶
func (b *InMemoryBackend) Restart(name string) error
Restart discards the running host; the next request starts a fresh one.
func (*InMemoryBackend) Restore ¶
func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error
Restore loads a snapshot, replacing every app; hosts start again on first use.
func (*InMemoryBackend) ServeHTTP ¶
func (b *InMemoryBackend) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP routes a request to an app's function host or its Kudu API.
func (*InMemoryBackend) SetFunctionKey ¶
func (b *InMemoryBackend) SetFunctionKey(name, fn, keyName, value string) (string, error)
SetFunctionKey creates or replaces a function key; an empty value generates one.
func (*InMemoryBackend) SetHostKey ¶
func (b *InMemoryBackend) SetHostKey(name, keyType, keyName, value string) (string, error)
SetHostKey creates or replaces a host key; an empty value generates one. It returns the stored value.
func (*InMemoryBackend) SetOnClose ¶
func (b *InMemoryBackend) SetOnClose(fn func())
SetOnClose registers a hook run by Close after every container is stopped.
func (*InMemoryBackend) SetPortPool ¶
func (b *InMemoryBackend) SetPortPool(p PortPool)
SetPortPool wires the host port source for published containers.
func (*InMemoryBackend) SetRuntime ¶
func (b *InMemoryBackend) SetRuntime(fn func() (Runner, error))
SetRuntime wires the container runtime source; nil disables function hosts.
func (*InMemoryBackend) SetSettings ¶
func (b *InMemoryBackend) SetSettings(name string, settings map[string]string) error
SetSettings replaces the app's application settings; a running host restarts on its next request.
func (*InMemoryBackend) SetStopped ¶
func (b *InMemoryBackend) SetStopped(name string, stopped bool) error
SetStopped starts (false) or stops (true) the app.
type Provider ¶
type Provider struct{}
Provider implements service.Provider for Azure Functions.
func (*Provider) Init ¶
func (p *Provider) Init(ctx *service.AppContext) (service.Registerable, error)
Init builds the backend and handler; the port is bound by Handler.StartWorker.
type Settings ¶
type Settings struct {
Engine string `` //nolint:lll // config struct tags are intentionally verbose
/* 229-byte string literal not displayed */
Domain string `` //nolint:lll // config struct tags are intentionally verbose
/* 300-byte string literal not displayed */
Port int `` //nolint:lll // config struct tags are intentionally verbose
/* 256-byte string literal not displayed */
StartupTimeout time.Duration `` //nolint:lll // config struct tags are intentionally verbose
/* 226-byte string literal not displayed */
}
Settings is the Kong-embedded configuration of the Azure Functions emulator.
func DefaultSettings ¶
func DefaultSettings() Settings
DefaultSettings returns the settings used when no ConfigProvider is available.