Documentation
¶
Index ¶
- Constants
- Variables
- type APIError
- type Action
- type ActionList
- type ConfigProvider
- type Delivery
- type Event
- type FunctionInvoker
- 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
- func (h *Handler) Trusted() echo.HandlerFunc
- type InMemoryBackend
- func (b *InMemoryBackend) ChangeRuleCompartment(id, ifMatch string, in changeCompartmentIn) error
- func (b *InMemoryBackend) Compartments() []string
- func (b *InMemoryBackend) CreateRule(in createRuleIn) (RuleWire, string, error)
- func (b *InMemoryBackend) DeleteRule(id, ifMatch string) error
- func (b *InMemoryBackend) Deliveries() []Delivery
- func (b *InMemoryBackend) Emit(ev Event)
- func (b *InMemoryBackend) GetRule(id string) (RuleWire, string, error)
- func (b *InMemoryBackend) ListRules(compartment, name, state string, o ListOpts) (page.Page[RuleSummaryWire], error)
- 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) SetCompartmentChecker(fn func(string) bool)
- func (b *InMemoryBackend) SetCompartmentTree(fn func(id, ancestor string) bool)
- func (b *InMemoryBackend) SetDispatcher(fn func(func()))
- func (b *InMemoryBackend) SetFunctionInvoker(f FunctionInvoker)
- func (b *InMemoryBackend) SetNotifier(n Notifier)
- func (b *InMemoryBackend) SetStreamer(s Streamer)
- func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte
- func (b *InMemoryBackend) UpdateRule(id, ifMatch string, in updateRuleIn) (RuleWire, string, error)
- func (b *InMemoryBackend) Wait()
- type ListOpts
- type Notifier
- type Provider
- type Rule
- type RuleSummaryWire
- type RuleWire
- type Settings
- type Streamer
- type Tags
Constants ¶
const DefaultPort = 8164
DefaultPort is the dedicated listener's default TCP port.
const (
// Region is the fixed region baked into emulated OCIDs.
Region = "us-ashburn-1"
)
Variables ¶
var ErrNilAppContext = errors.New("ocievents: nil app context")
ErrNilAppContext is returned when Init is called with a nil AppContext.
var ErrSnapshotNull = errors.New("ocievents: 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 Action ¶
type Action struct {
ID string `json:"id"`
ActionType string `json:"actionType"`
State string `json:"lifecycleState"`
Message string `json:"lifecycleMessage"`
Description string `json:"description,omitempty"`
TopicID string `json:"topicId,omitempty"`
StreamID string `json:"streamId,omitempty"`
FunctionID string `json:"functionId,omitempty"`
IsEnabled bool `json:"isEnabled"`
}
Action is one destination of a rule.
type ActionList ¶
type ActionList struct {
Actions []*Action `json:"actions"`
}
ActionList is the wire wrapper of a rule's actions.
type ConfigProvider ¶
type ConfigProvider interface {
GetOCIEventsSettings() Settings
}
ConfigProvider extracts OCI Events configuration from the AppContext Config.
type Delivery ¶
type Delivery struct {
Time time.Time `json:"time"`
EventID string `json:"eventId"`
EventType string `json:"eventType"`
RuleID string `json:"ruleId"`
ActionID string `json:"actionId"`
ActionType string `json:"actionType"`
TargetID string `json:"targetId"`
Status string `json:"status"`
Error string `json:"error,omitempty"`
}
Delivery records one attempt to hand an event to a rule action; failed attempts are not retried.
type Event ¶
type Event struct {
Time time.Time
AdditionalDetails map[string]any
EventType string
Source string
CompartmentID string
ResourceName string
ResourceID string
AvailabilityDomain string
}
Event is what a service reports; the backend wraps it in the OCI event envelope.
type FunctionInvoker ¶
type FunctionInvoker interface {
FunctionActive(id string) bool
InvokeFunction(ctx context.Context, functionID string, body []byte) error
}
FunctionInvoker invokes a function with an event as its payload; wired to OCI Functions in internal/app.
type Handler ¶
type Handler struct {
Backend *InMemoryBackend
Port int
EnforceAuth bool
// contains filtered or unexported fields
}
Handler serves OCI Events: rules and the event delivery log.
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 OCIEvents requests.
func (*Handler) MatchPriority ¶
MatchPriority is irrelevant because RouteMatcher never matches.
func (*Handler) RouteMatcher ¶
RouteMatcher never matches: OCIEvents runs on its own listener.
func (*Handler) Snapshot ¶
Snapshot implements persistence.Persistable by delegating to the backend.
func (*Handler) StartWorker ¶
StartWorker binds the dedicated listener synchronously so a port conflict is returned to the caller.
func (*Handler) Trusted ¶
func (h *Handler) Trusted() echo.HandlerFunc
Trusted returns a handler that skips request-signature verification, for the in-process dashboard proxy.
type InMemoryBackend ¶
InMemoryBackend holds every rule under one lock.
func NewInMemoryBackend ¶
func NewInMemoryBackend() *InMemoryBackend
NewInMemoryBackend creates an empty backend that delivers events on goroutines tracked by Wait.
func (*InMemoryBackend) ChangeRuleCompartment ¶
func (b *InMemoryBackend) ChangeRuleCompartment(id, ifMatch string, in changeCompartmentIn) error
ChangeRuleCompartment moves a rule.
func (*InMemoryBackend) Compartments ¶
func (b *InMemoryBackend) Compartments() []string
Compartments lists the distinct compartments that hold rules.
func (*InMemoryBackend) CreateRule ¶
func (b *InMemoryBackend) CreateRule(in createRuleIn) (RuleWire, string, error)
CreateRule creates a rule.
func (*InMemoryBackend) DeleteRule ¶
func (b *InMemoryBackend) DeleteRule(id, ifMatch string) error
DeleteRule deletes a rule; it stays readable with state DELETED.
func (*InMemoryBackend) Deliveries ¶
func (b *InMemoryBackend) Deliveries() []Delivery
Deliveries returns the delivery log, oldest first.
func (*InMemoryBackend) Emit ¶
func (b *InMemoryBackend) Emit(ev Event)
Emit matches an event against every enabled rule that covers its compartment and delivers it to the enabled actions of each matching rule.
func (*InMemoryBackend) GetRule ¶
func (b *InMemoryBackend) GetRule(id string) (RuleWire, string, error)
GetRule returns one rule and its etag; a deleted rule is still reported with state DELETED.
func (*InMemoryBackend) ListRules ¶
func (b *InMemoryBackend) ListRules(compartment, name, state string, o ListOpts) (page.Page[RuleSummaryWire], error)
ListRules lists the rules of a compartment; DELETED rules are hidden unless filtered for.
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 for timestamps and delivery records.
func (*InMemoryBackend) SetCompartmentChecker ¶
func (b *InMemoryBackend) SetCompartmentChecker(fn func(string) bool)
SetCompartmentChecker validates compartmentId arguments against another service (OCI Identity).
func (*InMemoryBackend) SetCompartmentTree ¶
func (b *InMemoryBackend) SetCompartmentTree(fn func(id, ancestor string) bool)
SetCompartmentTree tells the backend whether a compartment is nested below another (OCI Identity).
func (*InMemoryBackend) SetDispatcher ¶
func (b *InMemoryBackend) SetDispatcher(fn func(func()))
SetDispatcher replaces how deliveries are run; tests pass a function that runs them inline.
func (*InMemoryBackend) SetFunctionInvoker ¶
func (b *InMemoryBackend) SetFunctionInvoker(f FunctionInvoker)
SetFunctionInvoker wires the FAAS action target.
func (*InMemoryBackend) SetNotifier ¶
func (b *InMemoryBackend) SetNotifier(n Notifier)
SetNotifier wires the ONS action target.
func (*InMemoryBackend) SetStreamer ¶
func (b *InMemoryBackend) SetStreamer(s Streamer)
SetStreamer wires the OSS action target.
func (*InMemoryBackend) Snapshot ¶
func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte
Snapshot serialises the rules and registered API keys; the delivery log is not persisted.
func (*InMemoryBackend) UpdateRule ¶
func (b *InMemoryBackend) UpdateRule(id, ifMatch string, in updateRuleIn) (RuleWire, string, error)
UpdateRule changes the mutable attributes of a rule.
func (*InMemoryBackend) Wait ¶
func (b *InMemoryBackend) Wait()
Wait blocks until every in-flight delivery has finished.
type Notifier ¶
Notifier publishes an event message to an ONS topic; wired to OCI Notifications in internal/app.
type Provider ¶
type Provider struct{}
Provider implements service.Provider for OCI Events. 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 Rule ¶
type Rule struct {
TimeCreated time.Time `json:"timeCreated"`
Tags Tags `json:"tags"`
ID string `json:"id"`
DisplayName string `json:"displayName"`
Description string `json:"description,omitempty"`
Condition string `json:"condition"`
CompartmentID string `json:"compartmentId"`
State string `json:"state"`
Etag string `json:"etag"`
Actions []*Action `json:"actions"`
Seq int64 `json:"seq"`
IsEnabled bool `json:"isEnabled"`
}
Rule is an Events rule.
type RuleSummaryWire ¶
type RuleSummaryWire struct {
TimeCreated time.Time `json:"timeCreated"`
DefinedTags map[string]map[string]any `json:"definedTags,omitempty"`
FreeformTags map[string]string `json:"freeformTags,omitempty"`
ID string `json:"id"`
DisplayName string `json:"displayName"`
Description string `json:"description,omitempty"`
Condition string `json:"condition"`
CompartmentID string `json:"compartmentId"`
LifecycleState string `json:"lifecycleState"`
IsEnabled bool `json:"isEnabled"`
}
RuleSummaryWire is the wire form of a rule in a list.
type RuleWire ¶
type RuleWire struct {
TimeCreated time.Time `json:"timeCreated"`
DefinedTags map[string]map[string]any `json:"definedTags,omitempty"`
FreeformTags map[string]string `json:"freeformTags,omitempty"`
ID string `json:"id"`
DisplayName string `json:"displayName"`
Description string `json:"description,omitempty"`
Condition string `json:"condition"`
CompartmentID string `json:"compartmentId"`
LifecycleState string `json:"lifecycleState"`
LifecycleMessage string `json:"lifecycleMessage"`
Actions ActionList `json:"actions"`
IsEnabled bool `json:"isEnabled"`
}
RuleWire is the wire form of a rule.
type Settings ¶
type Settings struct {
Port int `` //nolint:lll // config struct tags are intentionally verbose
/* 180-byte string literal not displayed */
EnforceAuth bool `` //nolint:lll // config struct tags are intentionally verbose
/* 236-byte string literal not displayed */
}
Settings holds service-level configuration, embedded in the root CLI as CLI.OCIEvents.
func DefaultSettings ¶
func DefaultSettings() Settings
DefaultSettings returns the settings used when no ConfigProvider is available.