Help us shape the future of Go! Take the 2026 Go Developer Survey

ocifunctions

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 36 Imported by: 0

README

OCI Functions

Parity grade: B · SDK github.com/oracle/oci-go-sdk/v65@v65.126.2 · last audited 2026-10-25 (bfe657153)

Coverage

Metric Value
PARITY entries audited 16 (9 ok, 7 partial)
Feature families 9 (7 ok, 2 partial)
Known gaps 9
Deferred items 0
Resource leaks unknown
Known gaps
  • Pre-built function sources (PRE_BUILT_FUNCTIONS), archive sources, the pbfListings, functionsRuntimes and triggers APIs are not implemented; CreateFunction accepts only CONTAINER_IMAGE.
  • Provisioned concurrency, failure and success destinations, syslogUrl, traceConfig, logging and imagePolicyConfig are stored and returned but have no effect: containers are not pre-warmed, detached results are not delivered to streams, queues or notifications, function output is not forwarded to syslog and image signatures are not verified.
  • memoryInMBs is passed to the function as FN_MEMORY and FN_TMPSIZE is always 0; neither is enforced as a container memory or tmp limit, and shape (CPU architecture) does not select a platform.
  • The HTTP status of failed and timed out sync invocations (502 FunctionInvokeExecutionFailed, 504 FunctionInvokeTimeout), the 429 throttling code, 503 for an unavailable engine, the 6 MiB payload limit and the exact response headers (Fn-Http-Status and Fn-Http-H-* are passed through, status stays 200) are unverified against the live service.
  • The FDK socket is shared through a bind mount, so the container runtime must run on the same host as the emulator (not Docker Desktop VMs or a remote daemon).
  • Function stdout and stderr are not captured or exposed; there is no Fn-Fdk-Version/Fn-Fdk-Runtime handling and no cloudevent-specific request shaping for fn-intent.
  • Subnet, network security group, KMS key and image registry references are stored without being resolved against other emulated services; an image is whatever the container runtime can pull.
  • Application and function name syntax, per-tenancy limits, opc-retry-token idempotency, IAM policy checks, resource principals and instance principals are not applied; only API-key signatures are verified.
  • Tag values and defined-tag namespaces are stored verbatim, not validated against a tag namespace.

More

Documentation

Index

Constants

View Source
const (
	// DefaultPort is the dedicated listener's default TCP port.
	DefaultPort = 8154
	// DefaultStartupTimeout bounds image pull plus container start until the FDK socket accepts calls.
	DefaultStartupTimeout = 5 * time.Minute
	// DefaultIdleTimeout is how long an unused warm container is kept.
	DefaultIdleTimeout = 10 * time.Minute
	// DefaultMaxContainers caps live function containers (busy and warm).
	DefaultMaxContainers = 32
)
View Source
const (
	// Region is the fixed region baked into emulated OCIDs.
	Region = "us-ashburn-1"
)

Variables

View Source
var ErrNilAppContext = errors.New("ocifunctions: nil app context")

ErrNilAppContext is returned when Init is called with a nil AppContext.

View Source
var ErrSnapshotNull = errors.New("ocifunctions: null entry in snapshot")

ErrSnapshotNull is returned when a snapshot contains a null entry.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	Code    string
	Message string
	Status  int
}

APIError is an OCI error response: HTTP status plus the `code` and `message` body fields.

func (*APIError) Error

func (e *APIError) Error() string

type Application

type Application struct {
	TimeCreated   time.Time         `json:"timeCreated"`
	TimeUpdated   time.Time         `json:"timeUpdated"`
	TransitionAt  *time.Time        `json:"transitionAt,omitempty"`
	TraceConfig   *TraceConfig      `json:"traceConfig,omitempty"`
	Logging       *LoggingConfig    `json:"logging,omitempty"`
	ImagePolicy   *ImagePolicy      `json:"imagePolicy,omitempty"`
	Config        map[string]string `json:"config,omitempty"`
	Tags          Tags              `json:"tags"`
	ID            string            `json:"id"`
	CompartmentID string            `json:"compartmentId"`
	Name          string            `json:"name"`
	State         string            `json:"state"`
	Shape         string            `json:"shape"`
	SyslogURL     string            `json:"syslogUrl,omitempty"`
	Etag          string            `json:"etag"`
	SubnetIDs     []string          `json:"subnetIds"`
	NSGIDs        []string          `json:"networkSecurityGroupIds,omitempty"`
	Seq           int64             `json:"seq"`
}

Application is a group of functions sharing network and configuration.

type Concurrency

type Concurrency struct {
	Count    *int   `json:"count,omitempty"`
	Strategy string `json:"strategy"`
}

Concurrency is a function's provisioned concurrency configuration.

type ConfigProvider

type ConfigProvider interface {
	GetOCIFunctionsSettings() Settings
}

ConfigProvider extracts OCI Functions configuration from the AppContext Config.

type Function

type Function struct {
	Tags          Tags              `json:"tags"`
	TimeUpdated   time.Time         `json:"timeUpdated"`
	TimeCreated   time.Time         `json:"timeCreated"`
	TransitionAt  *time.Time        `json:"transitionAt,omitempty"`
	TraceConfig   *TraceConfig      `json:"traceConfig,omitempty"`
	Detached      *int              `json:"detachedModeTimeoutInSeconds,omitempty"`
	Config        map[string]string `json:"config,omitempty"`
	Provisioned   Concurrency       `json:"provisionedConcurrencyConfig"`
	ID            string            `json:"id"`
	AppID         string            `json:"applicationId"`
	CompartmentID string            `json:"compartmentId"`
	Name          string            `json:"name"`
	State         string            `json:"state"`
	Image         string            `json:"image"`
	ImageDigest   string            `json:"imageDigest,omitempty"`
	Etag          string            `json:"etag"`
	Success       json.RawMessage   `json:"successDestination,omitempty"`
	Failure       json.RawMessage   `json:"failureDestination,omitempty"`
	Memory        int64             `json:"memoryInMBs"`
	Seq           int64             `json:"seq"`
	Timeout       int               `json:"timeoutInSeconds"`
}

Function is a container-image function of an application.

type Handler

type Handler struct {
	Backend *InMemoryBackend

	Port        int
	EnforceAuth bool
	// contains filtered or unexported fields
}

Handler serves OCI Functions: applications, functions and function invocation.

func NewHandler

func NewHandler(backend *InMemoryBackend) *Handler

NewHandler creates a Handler; callers override Port and EnforceAuth from Settings.

func (*Handler) ExtractOperation

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

ExtractOperation returns the operation name for metrics.

func (*Handler) ExtractResource

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

ExtractResource returns the addressed resource id for metrics.

func (*Handler) GetSupportedOperations

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

GetSupportedOperations lists the supported operations.

func (*Handler) Handler

func (h *Handler) Handler() echo.HandlerFunc

Handler returns the Echo handler for all OCI Functions requests.

func (*Handler) MatchPriority

func (h *Handler) MatchPriority() int

MatchPriority is irrelevant because RouteMatcher never matches.

func (*Handler) Name

func (h *Handler) Name() string

Name returns the service name.

func (*Handler) Reset

func (h *Handler) Reset()

Reset clears all in-memory state.

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: OCI Functions runs on its own listener.

func (*Handler) Shutdown

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

Shutdown stops the listener and the sweeper.

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 dedicated listener synchronously so a port conflict is returned to the caller.

type ImagePolicy

type ImagePolicy struct {
	IsPolicyEnabled *bool       `json:"isPolicyEnabled"`
	KeyDetails      []KeyDetail `json:"keyDetails,omitempty"`
}

ImagePolicy is the image signature verification policy of an application.

type InMemoryBackend

type InMemoryBackend struct {
	Auth *ociauth.Registry
	// contains filtered or unexported fields
}

InMemoryBackend holds every application, function and work request under one lock.

func NewInMemoryBackend

func NewInMemoryBackend() *InMemoryBackend

NewInMemoryBackend creates an empty backend.

func (*InMemoryBackend) ChangeApplicationCompartment

func (b *InMemoryBackend) ChangeApplicationCompartment(id, ifMatch, compartment string) (string, error)

ChangeApplicationCompartment moves an application and its functions to another compartment.

func (*InMemoryBackend) Close

func (b *InMemoryBackend) Close()

Close stops detached invocations, removes every function container and releases the runtime.

func (*InMemoryBackend) Compartments

func (b *InMemoryBackend) Compartments() []string

Compartments lists the distinct compartments that hold applications or work requests.

func (*InMemoryBackend) Configure

func (b *InMemoryBackend) Configure(s Settings)

Configure applies the engine, timeout and capacity settings.

func (*InMemoryBackend) CreateApplication

func (b *InMemoryBackend) CreateApplication(in appIn) (appWire, string, string, error)

CreateApplication creates an application.

func (*InMemoryBackend) CreateFunction

func (b *InMemoryBackend) CreateFunction(in fnIn, endpoint string) (fnWire, string, string, error)

CreateFunction creates a function in an application.

func (*InMemoryBackend) DeleteApplication

func (b *InMemoryBackend) DeleteApplication(id, ifMatch string) (string, error)

DeleteApplication moves an empty application to DELETING.

func (*InMemoryBackend) DeleteFunction

func (b *InMemoryBackend) DeleteFunction(id, ifMatch string) (string, error)

DeleteFunction moves a function to DELETING and removes its warm containers.

func (*InMemoryBackend) GetApplication

func (b *InMemoryBackend) GetApplication(id string) (appWire, string, error)

GetApplication returns one application.

func (*InMemoryBackend) GetFunction

func (b *InMemoryBackend) GetFunction(id, endpoint string) (fnWire, string, error)

GetFunction returns one function.

func (*InMemoryBackend) GetWorkRequest

func (b *InMemoryBackend) GetWorkRequest(id string) (workRequestWire, error)

GetWorkRequest returns one work request.

func (*InMemoryBackend) Invoke

func (b *InMemoryBackend) Invoke(ctx context.Context, fnID string, in InvokeIn) (InvokeOut, error)

Invoke runs a function: synchronously it returns the function's response, detached it returns once the call is accepted and the function runs in the background.

func (*InMemoryBackend) ListApplications

func (b *InMemoryBackend) ListApplications(
	compartment, id, name, state string,
	o ListOpts,
) (page.Page[appWire], error)

ListApplications lists the applications of a compartment.

func (*InMemoryBackend) ListFunctions

func (b *InMemoryBackend) ListFunctions(
	appID, id, name, state, endpoint string,
	o ListOpts,
) (page.Page[fnWire], error)

ListFunctions lists the functions of an application.

func (*InMemoryBackend) ListWorkRequests

func (b *InMemoryBackend) ListWorkRequests(
	compartment, resourceID, id string, o ListOpts,
) (page.Page[workRequestWire], error)

ListWorkRequests lists the work requests of a compartment, optionally for one resource.

func (*InMemoryBackend) LiveContainers

func (b *InMemoryBackend) LiveContainers() int

LiveContainers reports how many function containers exist (busy plus warm).

func (*InMemoryBackend) ReapIdle

func (b *InMemoryBackend) ReapIdle()

ReapIdle removes warm containers unused for longer than the idle timeout.

func (*InMemoryBackend) Reset

func (b *InMemoryBackend) Reset()

Reset clears all state and removes every function container.

func (*InMemoryBackend) Restore

func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error

Restore loads backend state from a snapshot.

func (*InMemoryBackend) SetClock

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

SetClock injects the time source used for lifecycle transitions and warm-container expiry.

func (*InMemoryBackend) SetOnClose

func (b *InMemoryBackend) SetOnClose(fn func())

SetOnClose registers a callback run by Close, used to release the runtime client.

func (*InMemoryBackend) SetRuntime

func (b *InMemoryBackend) SetRuntime(fn func() (Runner, error))

SetRuntime installs the container runtime factory used to run functions.

func (*InMemoryBackend) SetTimeoutUnit

func (b *InMemoryBackend) SetTimeoutUnit(d time.Duration)

SetTimeoutUnit changes what one function timeout second lasts; tests shrink it to exercise timeouts quickly.

func (*InMemoryBackend) SetTransition

func (b *InMemoryBackend) SetTransition(d time.Duration)

SetTransition sets how long CREATING and DELETING states last.

func (*InMemoryBackend) Snapshot

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

Snapshot serialises the backend state, including registered API keys. Containers are not persisted.

func (*InMemoryBackend) Sweep

func (b *InMemoryBackend) Sweep()

Sweep applies lifecycle transitions and drops containers of deleted functions.

func (*InMemoryBackend) UpdateApplication

func (b *InMemoryBackend) UpdateApplication(id, ifMatch string, in appIn) (string, error)

UpdateApplication (202, no body) changes the mutable fields of an application.

func (*InMemoryBackend) UpdateFunction

func (b *InMemoryBackend) UpdateFunction(id, ifMatch string, in fnIn) (string, error)

UpdateFunction (202, no body) changes the mutable fields of a function; a new image replaces the warm containers.

func (*InMemoryBackend) WorkRequestExists

func (b *InMemoryBackend) WorkRequestExists(id string) error

WorkRequestExists reports whether a work request exists (its error list is always empty).

func (*InMemoryBackend) WorkRequestLogs

func (b *InMemoryBackend) WorkRequestLogs(id string, o ListOpts) (page.Page[wrLogWire], error)

WorkRequestLogs returns the log entries of a work request.

type InvokeIn

type InvokeIn struct {
	Header   http.Header
	URL      string
	Body     []byte
	Detached bool
	DryRun   bool
}

InvokeIn is one invocation request.

type InvokeOut

type InvokeOut struct {
	Header http.Header
	CallID string
	Body   []byte
	Status int
}

InvokeOut is the function's response.

type KeyDetail

type KeyDetail struct {
	KmsKeyID string `json:"kmsKeyId"`
}

KeyDetail references a KMS key trusted by the image policy.

type ListOpts

type ListOpts struct {
	SortBy string
	Order  string
	Page   string
	Limit  int
}

ListOpts carries the shared list query parameters.

type LoggingConfig

type LoggingConfig struct {
	LineFormat string `json:"lineFormat,omitempty"`
}

LoggingConfig is the application logging configuration.

type Provider

type Provider struct{}

Provider implements service.Provider for OCI Functions. It runs on its own listener (see Handler.StartWorker) and never matches on the shared AWS router.

func (*Provider) Init

Init creates the backend and handler; the port is bound in StartWorker.

func (*Provider) Name

func (p *Provider) Name() string

Name returns the service provider name.

type Runner

type Runner = gcpserve.Runner

Runner is the slice of the container runtime that function execution needs.

type Settings

type Settings struct {
	StartupTimeout time.Duration `` //nolint:lll // config struct tags are intentionally verbose
	/* 184-byte string literal not displayed */
	IdleTimeout time.Duration `` //nolint:lll // config struct tags are intentionally verbose
	/* 173-byte string literal not displayed */
	Port int `` //nolint:lll // config struct tags are intentionally verbose
	/* 219-byte string literal not displayed */
	MaxContainers int `` //nolint:lll // config struct tags are intentionally verbose
	/* 218-byte string literal not displayed */
	DisableEngine bool `` //nolint:lll // config struct tags are intentionally verbose
	/* 184-byte string literal not displayed */
	EnforceAuth bool `` //nolint:lll // config struct tags are intentionally verbose
	/* 234-byte string literal not displayed */
}

Settings holds service-level configuration, embedded in the root CLI as CLI.OCIFunctions.

func DefaultSettings

func DefaultSettings() Settings

DefaultSettings returns the settings used when no ConfigProvider is available.

type Tags

type Tags struct {
	FreeformTags       map[string]string         `json:"freeformTags,omitempty"`
	DefinedTags        map[string]map[string]any `json:"definedTags,omitempty"`
	SecurityAttributes map[string]map[string]any `json:"securityAttributes,omitempty"`
}

Tags are the shared tag sets of a resource.

type TraceConfig

type TraceConfig struct {
	IsEnabled *bool   `json:"isEnabled,omitempty"`
	DomainID  *string `json:"domainId,omitempty"`
}

TraceConfig is the tracing configuration of an application or function.

type WorkRequest

type WorkRequest struct {
	Accepted      time.Time `json:"accepted"`
	FinishAt      time.Time `json:"finishAt"`
	ID            string    `json:"id"`
	Operation     string    `json:"operation"`
	CompartmentID string    `json:"compartmentId"`
	EntityType    string    `json:"entityType"`
	EntityID      string    `json:"entityId"`
	EntityURI     string    `json:"entityUri"`
	Action        string    `json:"action"`
	Seq           int64     `json:"seq"`
}

WorkRequest records an asynchronous operation that completes at FinishAt.

Jump to

Keyboard shortcuts

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