Documentation
¶
Index ¶
- Constants
- Variables
- type APIError
- type Application
- type Concurrency
- type ConfigProvider
- type Function
- type Handler
- func (h *Handler) ExtractOperation(c *echo.Context) string
- func (h *Handler) ExtractResource(c *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) Shutdown(ctx context.Context)
- func (h *Handler) Snapshot(ctx context.Context) []byte
- func (h *Handler) StartWorker(ctx context.Context) error
- type ImagePolicy
- type InMemoryBackend
- func (b *InMemoryBackend) ChangeApplicationCompartment(id, ifMatch, compartment string) (string, error)
- func (b *InMemoryBackend) Close()
- func (b *InMemoryBackend) Compartments() []string
- func (b *InMemoryBackend) Configure(s Settings)
- func (b *InMemoryBackend) CreateApplication(in appIn) (appWire, string, string, error)
- func (b *InMemoryBackend) CreateFunction(in fnIn, endpoint string) (fnWire, string, string, error)
- func (b *InMemoryBackend) DeleteApplication(id, ifMatch string) (string, error)
- func (b *InMemoryBackend) DeleteFunction(id, ifMatch string) (string, error)
- func (b *InMemoryBackend) GetApplication(id string) (appWire, string, error)
- func (b *InMemoryBackend) GetFunction(id, endpoint string) (fnWire, string, error)
- func (b *InMemoryBackend) GetWorkRequest(id string) (workRequestWire, error)
- func (b *InMemoryBackend) Invoke(ctx context.Context, fnID string, in InvokeIn) (InvokeOut, error)
- func (b *InMemoryBackend) ListApplications(compartment, id, name, state string, o ListOpts) (page.Page[appWire], error)
- func (b *InMemoryBackend) ListFunctions(appID, id, name, state, endpoint string, o ListOpts) (page.Page[fnWire], error)
- func (b *InMemoryBackend) ListWorkRequests(compartment, resourceID, id string, o ListOpts) (page.Page[workRequestWire], error)
- func (b *InMemoryBackend) LiveContainers() int
- func (b *InMemoryBackend) ReapIdle()
- func (b *InMemoryBackend) Reset()
- func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error
- func (b *InMemoryBackend) SetClock(now func() time.Time)
- func (b *InMemoryBackend) SetOnClose(fn func())
- func (b *InMemoryBackend) SetRuntime(fn func() (Runner, error))
- func (b *InMemoryBackend) SetTimeoutUnit(d time.Duration)
- func (b *InMemoryBackend) SetTransition(d time.Duration)
- func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte
- func (b *InMemoryBackend) Sweep()
- func (b *InMemoryBackend) UpdateApplication(id, ifMatch string, in appIn) (string, error)
- func (b *InMemoryBackend) UpdateFunction(id, ifMatch string, in fnIn) (string, error)
- func (b *InMemoryBackend) WorkRequestExists(id string) error
- func (b *InMemoryBackend) WorkRequestLogs(id string, o ListOpts) (page.Page[wrLogWire], error)
- type InvokeIn
- type InvokeOut
- type KeyDetail
- type ListOpts
- type LoggingConfig
- type Provider
- type Runner
- type Settings
- type Tags
- type TraceConfig
- type WorkRequest
Constants ¶
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 )
const (
// Region is the fixed region baked into emulated OCIDs.
Region = "us-ashburn-1"
)
Variables ¶
var ErrNilAppContext = errors.New("ocifunctions: nil app context")
ErrNilAppContext is returned when Init is called with a nil AppContext.
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 ¶
APIError is an OCI error response: HTTP status plus the `code` and `message` body fields.
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 ¶
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 ¶
ExtractOperation returns the operation name for metrics.
func (*Handler) ExtractResource ¶
ExtractResource returns the addressed resource id for metrics.
func (*Handler) GetSupportedOperations ¶
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 ¶
MatchPriority is irrelevant because RouteMatcher never matches.
func (*Handler) RouteMatcher ¶
RouteMatcher never matches: OCI Functions runs on its own listener.
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 ¶
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 ¶
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 ¶
WorkRequestLogs returns the log entries of a work request.
type KeyDetail ¶
type KeyDetail struct {
KmsKeyID string `json:"kmsKeyId"`
}
KeyDetail references a KMS key trusted by the image policy.
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 ¶
func (p *Provider) Init(ctx *service.AppContext) (service.Registerable, error)
Init creates the backend and handler; the port is bound in StartWorker.
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.