ocifunctions

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: 43 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

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 2
Deferred items 0
Resource leaks unknown
Known gaps
  • Pre-built function sources (PRE_BUILT_FUNCTIONS), archive sources (ARCHIVE with runtimeConfig), the pbfListings, functionsRuntimes and triggers APIs are not implemented and CreateFunction accepts only CONTAINER_IMAGE: they need Oracle-published content the emulator has no source for (the PBF catalog and its Oracle-hosted images, the runtime catalog and Oracle's function build service); the pinned SDK types are functions/create_pre_built_function_source_details.go, create_archive_function_source_details.go, pbf_listing.go and functions_runtime.go.
  • IAM policy checks, resource principals and instance principals are not applied; only API-key signatures are verified.

More

Documentation

Index

Constants

View Source
const (
	EventCreateApplication = "com.oraclecloud.functions.createapplication"
	EventDeleteApplication = "com.oraclecloud.functions.deleteapplication"
	EventCreateFunction    = "com.oraclecloud.functions.createfunction"
	EventDeleteFunction    = "com.oraclecloud.functions.deletefunction"
	EventUpdateApplication = "com.oraclecloud.functions.updateapplication"
	EventUpdateFunction    = "com.oraclecloud.functions.updatefunction"

	EventChangeApplicationCompartment = "com.oraclecloud.functions.changeapplicationcompartment"
)

Event types (https://docs.oracle.com/en-us/iaas/Content/Events/Reference/eventsproducers.htm).

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
	// DefaultMaxApplications and DefaultMaxFunctions are the application-count and function-count limits.
	DefaultMaxApplications = 20
	DefaultMaxFunctions    = 500
	// DefaultConcurrencyMB and DefaultProvisionedMB are the total-concurrency-mb and provisioned-concurrency-mb limits.
	DefaultConcurrencyMB = 60 * 1024
	DefaultProvisionedMB = 40 * 1024
)
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 Destinations

type Destinations struct {
	Stream func(ctx context.Context, streamID string, value []byte) error
	Queue  func(ctx context.Context, queueID, channelID, content string) error
	Notify func(ctx context.Context, topicID, title, body string) error
	Exists func(kind, id string) bool
}

Destinations delivers detached invocation results to other emulated OCI services and checks targets exist.

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       jsontext.Value    `json:"successDestination,omitempty"`
	Failure       jsontext.Value    `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 ImageInfo

type ImageInfo struct {
	ID     string
	Digest string
}

ImageInfo identifies an image held by the emulated container registry.

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 Images

type Images struct {
	// Resolve reports whether the reference names a stored image; owned is false for references outside the
	// emulated tenancy namespace.
	Resolve func(ref string) (img ImageInfo, found, owned bool)
	// Verified reports whether the image carries a valid signature made by one of the keys.
	Verified func(img ImageInfo, keyIDs []string) bool
}

Images resolves function images against the emulated container registry and verifies their signatures.

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

func (b *InMemoryBackend) FunctionActive(id string) bool

FunctionActive reports whether id is a function that is not deleted or being deleted.

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

func (b *InMemoryBackend) SetDestinations(d Destinations)

SetDestinations delivers detached results to OCI Streaming, Queue and Notifications.

func (*InMemoryBackend) SetEventSink

func (b *InMemoryBackend) SetEventSink(fn func(ResourceEvent))

SetEventSink installs the receiver of resource events; it is called outside the backend lock.

func (*InMemoryBackend) SetImages

func (b *InMemoryBackend) SetImages(i Images)

SetImages validates function images and image policy signatures against OCI Artifacts.

func (*InMemoryBackend) SetInvokeObserver

func (b *InMemoryBackend) SetInvokeObserver(fn InvokeObserver)

SetInvokeObserver registers the observer; nil removes it.

func (*InMemoryBackend) SetKeyChecker

func (b *InMemoryBackend) SetKeyChecker(fn func(keyID string) (string, bool))

SetKeyChecker makes image policy kmsKeyId values validated against OCI Vault: fn returns the key's state.

func (*InMemoryBackend) SetLogSink

func (b *InMemoryBackend) SetLogSink(fn func(LogLine) int)

SetLogSink installs the receiver of function output lines (OCI Logging); it returns how many logs took the line.

func (*InMemoryBackend) SetNetwork

func (b *InMemoryBackend) SetNetwork(n Network)

SetNetwork validates application subnets and network security groups against OCI Core.

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

func (b *InMemoryBackend) SetTagLookup(fn ocitags.Lookup)

SetTagLookup wires defined-tag validation against a tag namespace source (OCI Identity); nil accepts any namespace.

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 InvokeEvent

type InvokeEvent struct {
	Time         time.Time
	AppID        string
	AppName      string
	FunctionID   string
	FunctionName string
	CallID       string
	ErrorCode    string
	ErrorMessage string
	Duration     time.Duration
	Status       int
}

InvokeEvent describes one finished function invocation.

type InvokeIn

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

InvokeIn is one invocation request.

type InvokeObserver

type InvokeObserver func(InvokeEvent)

InvokeObserver receives every finished invocation, successful or not.

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 LogLine

type LogLine struct {
	Time         time.Time
	AppID        string
	AppName      string
	FunctionID   string
	FunctionName string
	CallID       string
	Stream       string
	Text         string
	LineFormat   string
}

LogLine is one line a function wrote to stdout or stderr during an invocation.

type LoggingConfig

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

LoggingConfig is the application logging configuration.

type Network

type Network struct {
	Subnet func(id string) (vcnID string, ok bool)
	NSG    func(id string) (vcnID string, ok bool)
}

Network resolves subnets and network security groups of OCI Core; each returns the owning VCN.

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 ResourceEvent

type ResourceEvent struct {
	Time          time.Time
	EventType     string
	CompartmentID string
	ResourceName  string
	ResourceID    string
}

ResourceEvent describes an application or function lifecycle change.

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
	/* 188-byte string literal not displayed */
	IdleTimeout time.Duration `` //nolint:lll // config struct tags are intentionally verbose
	/* 177-byte string literal not displayed */
	Port int `` //nolint:lll // config struct tags are intentionally verbose
	/* 223-byte string literal not displayed */
	MaxContainers int `` //nolint:lll // config struct tags are intentionally verbose
	/* 222-byte string literal not displayed */
	MaxApplications int `` //nolint:lll // config struct tags are intentionally verbose
	/* 176-byte string literal not displayed */
	MaxFunctions int `` //nolint:lll // config struct tags are intentionally verbose
	/* 170-byte string literal not displayed */
	ConcurrencyMB int64 `` //nolint:lll // config struct tags are intentionally verbose
	/* 218-byte string literal not displayed */
	ProvisionedMB int64 `` //nolint:lll // config struct tags are intentionally verbose
	/* 209-byte string literal not displayed */
	DisableEngine bool `` //nolint:lll // config struct tags are intentionally verbose
	/* 188-byte string literal not displayed */
	EnforceAuth bool `` //nolint:lll // config struct tags are intentionally verbose
	/* 238-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