azurefunctions

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 42 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Azure Functions

Parity grade: B · SDK azure-sdk-for-go/sdk/resourcemanager/appservice/armappservice/v6@v6.0.0 · last audited 2026-11-05 (959104c86)

Coverage

Metric Value
PARITY entries audited 17 (17 ok)
Feature families 10 (10 ok)
Known gaps 4
Deferred items 0
Resource leaks ok
Known gaps
  • Bundle-extension triggers other than timer, queue, blob, Service Bus and Event Hubs (Cosmos DB, Event Grid and the rest) are not exercised against a real host (triggers_docker_test.go).
  • Not implemented: VNet integration, custom domains and certificates, easy auth (authsettings are stored only); Flex Consumption deployment.storage is validated but not used as the package store, and alwaysReady, maximumInstanceCount and perInstanceConcurrency have no runtime effect.
  • Deployment slots: no slot-level custom domains (custom domains are not implemented); slotsdiffs does not list the sticky-setting changes of the preview phases; only the swapped settings that differ are reported.
  • Web apps: Tomcat, JBoss, Ruby and Go stacks are rejected because the supported version matrix is not published on Learn (it comes from az webapp list-runtimes); Windows web apps, multi-container (sitecontainers) and docker-compose apps are rejected with 400.

More

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

View Source
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"
)
View Source
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
)
View Source
const SlotSep = "/"

SlotSep joins an app name and slot name into the data-plane name of a deployment slot.

Variables

View Source
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")
)
View Source
var ErrFunctionAppOnly = errors.New("azurefunctions: operation is only valid for function apps")

ErrFunctionAppOnly is returned by operations that only apply to function apps, not web apps.

View Source
var ErrFunctionInCode = errors.New(
	"azurefunctions: function is defined in code; remove it from the source and redeploy",
)

ErrFunctionInCode is returned when deleting a function that has no function.json in the deployed package.

Functions

func SlotName

func SlotName(app, slot string) string

SlotName is the data-plane name of an app's deployment slot.

func ValidateConfig

func ValidateConfig(cfg AppConfig) error

ValidateConfig reports whether the emulator can run the app's stack; function apps are validated at start.

Types

type AppConfig

type AppConfig struct {
	Kind            string
	LinuxFx         string
	AppCommandLine  string
	HealthCheckPath string
	ACRIdentityID   string
	Hosting         Hosting
	Flex            bool
	AlwaysOn        bool
	AlwaysReady     bool
	ACRManagedID    bool
}

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"`
	Log       string    `json:"log,omitempty"`
	Succeeded bool      `json:"succeeded"`
}

Deployment is one Kudu deployment record.

type FunctionDef

type FunctionDef struct {
	Config map[string]any
	Name   string
}

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

func (h *Handler) ExtractOperation(*echo.Context) string

ExtractOperation implements service.Service.

func (*Handler) ExtractResource

func (h *Handler) ExtractResource(*echo.Context) string

ExtractResource implements service.Service.

func (*Handler) GetSupportedOperations

func (h *Handler) GetSupportedOperations() []string

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

func (h *Handler) MatchPriority() int

MatchPriority implements service.Registerable.

func (*Handler) Name

func (h *Handler) Name() string

Name implements service.Service.

func (*Handler) Reset

func (h *Handler) Reset()

Reset implements service.Resettable.

func (*Handler) Restore

func (h *Handler) Restore(ctx context.Context, data []byte) error

Restore implements persistence.Persistable by delegating to the backend.

func (*Handler) RouteMatcher

func (h *Handler) RouteMatcher() service.Matcher

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.

func (*Handler) Shutdown

func (h *Handler) Shutdown(ctx context.Context)

Shutdown implements service.Shutdowner.

func (*Handler) Snapshot

func (h *Handler) Snapshot(ctx context.Context) []byte

Snapshot implements persistence.Persistable by delegating to the backend.

func (*Handler) StartWorker

func (h *Handler) StartWorker(ctx context.Context) error

StartWorker binds the listener synchronously so a port conflict is returned to the caller.

type HostKeys

type HostKeys struct {
	FunctionKeys map[string]string
	SystemKeys   map[string]string
	MasterKey    string
}

HostKeys are an app's host-level keys.

type Hosting

type Hosting string

Hosting is the plan family an app runs on; it decides when an idle host is unloaded.

const (
	HostingNone        Hosting = ""
	HostingConsumption Hosting = "Consumption"
	HostingFlex        Hosting = "Flex"
	HostingPremium     Hosting = "Premium"
	HostingDedicated   Hosting = "Dedicated"
)

Hosting values; the zero value means no idle policy (the host is kept until stopped or replaced).

type Identity

type Identity struct {
	TenantID          string
	SystemPrincipalID string
	User              []UserIdentity
}

Identity is the managed identity of an app.

type IdentityResolver

type IdentityResolver func(app string) (Identity, bool)

IdentityResolver returns the managed identity of the named app.

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) AdminToken

func (b *InMemoryBackend) AdminToken(name string) (string, error)

AdminToken returns a JWT the app's Functions host accepts as a bearer token on its /admin APIs.

func (*InMemoryBackend) App

func (b *InMemoryBackend) App(name string) (AppInfo, bool)

App returns the app's data-plane view.

func (*InMemoryBackend) Build

func (b *InMemoryBackend) Build(ctx context.Context, name string, zipData []byte) ([]byte, string, error)

Build installs the package's dependencies in a throwaway container of the app's runtime image and returns the rebuilt zip and the build log.

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) DeleteFunction

func (b *InMemoryBackend) DeleteFunction(ctx context.Context, name, fn string) error

DeleteFunction removes a function.json function's directory from the deployed package and restarts the host.

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) IsFlex

func (b *InMemoryBackend) IsFlex(name string) bool

IsFlex reports whether the app is on the Flex Consumption plan.

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

func (b *InMemoryBackend) PublishingCredentials(name string) (string, string, string, error)

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) ReapIdle

func (b *InMemoryBackend) ReapIdle() int

ReapIdle unloads the host of every app that has gone idle past its plan's limit and returns how many it took down. The next request starts the host again (a cold start). Apps with in-flight requests, with a stopped state, or whose triggers need the host are left alone.

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 (or, for background triggers, a fresh start) replaces it.

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) RunCommand

func (b *InMemoryBackend) RunCommand(ctx context.Context, name, command, dir string) (container.ExecResult, error)

RunCommand runs a shell command in dir inside the app's host container.

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) SetClock

func (b *InMemoryBackend) SetClock(now func() time.Time)

SetClock replaces the clock that idle reaping measures against.

func (*InMemoryBackend) SetConnectionStrings

func (b *InMemoryBackend) SetConnectionStrings(name string, env map[string]string) error

SetConnectionStrings replaces the app's connection strings, given as the prefixed environment variables the host sees (SQLCONNSTR_name and the like); a running host restarts on its next request.

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) SetHealthTiming

func (b *InMemoryBackend) SetHealthTiming(every, replaceAfter time.Duration)

SetHealthTiming sets how often a running web app's health check path is pinged and how long continuous failures last before the instance is replaced.

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) SetIdentity

func (b *InMemoryBackend) SetIdentity(r IdentityResolver, t TokenIssuer)

SetIdentity wires the managed identity lookup and token issuer behind the apps' local token service.

func (*InMemoryBackend) SetNetwork

func (b *InMemoryBackend) SetNetwork(n Network)

SetNetwork wires the container-visible address of the emulator's storage listeners.

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) SetRegistryExchanger

func (b *InMemoryBackend) SetRegistryExchanger(fn RegistryExchanger)

SetRegistryExchanger wires the registry token exchange behind managed-identity image pulls.

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) SetSlotHooks

func (b *InMemoryBackend) SetSlotHooks(
	rules func(app string) []RoutingRule, onDeploy func(ctx context.Context, name string),
)

SetSlotHooks wires what the data plane asks ARM about slots: the traffic routing rules of a production site and what to do after a deployment (auto swap).

func (*InMemoryBackend) SetStopped

func (b *InMemoryBackend) SetStopped(name string, stopped bool) error

SetStopped starts (false) or stops (true) the app.

func (*InMemoryBackend) Settings

func (b *InMemoryBackend) Settings(name string) (map[string]string, error)

Settings returns a copy of the app's application settings.

func (*InMemoryBackend) Snapshot

func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte

Snapshot serialises apps, settings, keys, deployments and package bytes; running hosts are not part of it.

func (*InMemoryBackend) SwapContent

func (b *InMemoryBackend) SwapContent(first, second string) error

SwapContent exchanges the deployed site content of two apps (or an app and its slot) and restarts both.

func (*InMemoryBackend) SyncTriggers

func (b *InMemoryBackend) SyncTriggers(ctx context.Context, name string) error

SyncTriggers refreshes the app's trigger metadata: it starts the host if needed and reads its function list.

func (*InMemoryBackend) WarmUp

func (b *InMemoryBackend) WarmUp(ctx context.Context, name string) error

WarmUp starts the app's host and waits until it answers, as a slot swap does before routing traffic. Apps that cannot be served here (stopped, no content, no container runtime) are skipped.

type Network

type Network struct {
	// Host is the address containers use for the emulator; empty picks the container runtime's default gateway.
	Host      string
	BlobPort  int
	QueuePort int
	TablePort int
}

Network tells function hosts how to reach the emulator's data-plane listeners from inside a container.

type PortPool

type PortPool = gcpserve.PortPool

PortPool hands out host ports for published containers.

type Provider

type Provider struct{}

Provider implements service.Provider for Azure Functions.

func (*Provider) Init

Init builds the backend and handler; the port is bound by Handler.StartWorker.

func (*Provider) Name

func (p *Provider) Name() string

Name returns the service provider name.

type RegistryExchanger

type RegistryExchanger func(ctx context.Context, registryHost, tenant, accessToken string) (string, error)

RegistryExchanger trades a Microsoft Entra access token for a registry refresh token at the login server's /oauth2/exchange endpoint, the way az acr login does.

type RoutingRule

type RoutingRule struct {
	Slot    string
	Percent float64
}

RoutingRule sends a share of a production site's traffic to one of its slots.

type Runner

type Runner = gcpserve.Runner

Runner is the slice of the container runtime that function apps need.

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 */
	ContainerHost string `` //nolint:lll // config struct tags are intentionally verbose
	/* 322-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.

type TokenIssuer

type TokenIssuer func(tenant, clientID, objectID, resource string) (string, time.Time, error)

TokenIssuer mints an access token for resource on behalf of the service principal objectID of clientID.

type UserIdentity

type UserIdentity struct {
	ResourceID  string
	ClientID    string
	PrincipalID string
}

UserIdentity is a user-assigned managed identity of an app.

type WebJobRun

type WebJobRun struct {
	Start  time.Time `json:"start"`
	End    time.Time `json:"end"`
	Job    string    `json:"job"`
	ID     string    `json:"id"`
	Status string    `json:"status"`
	Output string    `json:"output,omitempty"`
	Error  string    `json:"error,omitempty"`
}

WebJobRun is one run of a triggered WebJob.

Jump to

Keyboard shortcuts

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