event

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2021 License: MPL-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ServerName    string = "server_name" // ServerName: event source server name
	ServerAddress string = "server_addr" // ServerAddress: event source server address
)

Define a set of common keys and values to use in event payload maps. Having and using a common set will allow operators to more easily define event filters.

View Source
const (
	OpField          = "op"           // OpField in an event.
	RequestInfoField = "request_info" // RequestInfoField in an event.
	VersionField     = "version"      // VersionField in an event
	DetailsField     = "details"      // Details field in an event.
	HeaderField      = "header"       // HeaderField in an event.
	IdField          = "id"           // IdField in an event.
	CreatedAtField   = "created_at"   // CreatedAtField in an event.
	TypeField        = "type"         // TypeField in an event.

)

Variables

View Source
var (
	ErrInvalidParameter = errors.New("invalid parameter")
	ErrMaxRetries       = errors.New("too many retries")
	ErrIo               = errors.New("error during io operation")
	ErrRecordNotFound   = errors.New("record not found")
)

Functions

func InitSysEventer

func InitSysEventer(log hclog.Logger, c EventerConfig) error

InitSysEventer provides a mechanism to initialize a "system wide" eventer singleton for Boundary

func NewEventerContext

func NewEventerContext(ctx context.Context, eventer *Eventer) (context.Context, error)

NewEventerContext will return a context containing a value of the provided Eventer

func NewRequestInfoContext

func NewRequestInfoContext(ctx context.Context, info *RequestInfo) (context.Context, error)

NewRequestInfoContext will return a context containing a value for the provided RequestInfo

func TestResetSystEventer

func TestResetSystEventer(t *testing.T)

TestResetSysEventer will reset event.syseventer to an uninitialized state.

func WriteAudit

func WriteAudit(ctx context.Context, caller Op, opt ...Option) error

WriteAudit will write an audit event. It will first check the ctx for an eventer, then try event.SysEventer() and if no eventer can be found an error is returned.

At least one and any combination of the supported options may be used: WithRequest, WithResponse, WithAuth, WithId, WithFlush and WithRequestInfo. All other options are ignored.

func WriteError

func WriteError(ctx context.Context, caller Op, e error, opt ...Option)

WriteError will write an error event. It will first check the ctx for an eventer, then try event.SysEventer() and if no eventer can be found an hclog.Logger will be created and used.

The options WithId and WithRequestInfo are supported and all other options are ignored.

func WriteObservation

func WriteObservation(ctx context.Context, caller Op, opt ...Option) error

WriteObservation will write an observation event. It will first check the ctx for an eventer, then try event.SysEventer() and if no eventer can be found an error is returned.

At least one and any combination of the supported options may be used: WithHeader, WithDetails, WithId, WithFlush and WithRequestInfo. All other options are ignored.

func WriteSysEvent added in v0.4.0

func WriteSysEvent(ctx context.Context, caller Op, data map[string]interface{})

WriteSysEvent will write a sysevent using the eventer from event.SysEventer() if no eventer can be found an hclog.Logger will be created and used. This function should never be used when sending events while handling API requests.

Types

type Auth

type Auth struct {
	// AccessorId is a std audit field == auth_token public_id
	AccessorId string      `json:"accessor_id"`
	UserInfo   *UserInfo   `json:"user_info,omitempty"` // boundary field
	GrantsInfo *GrantsInfo `json:"grants_info,omitempty"`
	UserEmail  string      `json:"email,omitempty"`
	UserName   string      `json:"name,omitempty"`
}

type DeliveryGuarantee

type DeliveryGuarantee string // DeliveryGuarantee defines the guarantees around delivery of an event type within config
const (
	DefaultDeliveryGuarantee DeliveryGuarantee = ""            // DefaultDeliveryGuarantee will be BestEffort
	Enforced                 DeliveryGuarantee = "enforced"    // Enforced means that a delivery guarantee is enforced
	BestEffort               DeliveryGuarantee = "best-effort" // BestEffort means that a best effort will be made to deliver an event
)

type Eventer

type Eventer struct {
	// contains filtered or unexported fields
}

Eventer provides a method to send events to pipelines of sinks

func EventerFromContext

func EventerFromContext(ctx context.Context) (*Eventer, bool)

EventerFromContext attempts to get the eventer value from the context provided

func NewEventer

func NewEventer(log hclog.Logger, c EventerConfig, opt ...Option) (*Eventer, error)

NewEventer creates a new Eventer using the config. Supports options: WithNow

func SysEventer

func SysEventer() *Eventer

SysEventer returns the "system wide" eventer for Boundary.

func (*Eventer) FlushNodes

func (e *Eventer) FlushNodes(ctx context.Context) error

FlushNodes will flush any of the eventer's flushable nodes. This needs to be called whenever Boundary is stopping (aka shutting down).

func (*Eventer) Reopen

func (e *Eventer) Reopen() error

Reopen can used during a SIGHUP to reopen nodes, most importantly the underlying file sinks.

type EventerConfig

type EventerConfig struct {
	AuditDelivery       DeliveryGuarantee // AuditDelivery specifies the delivery guarantees for audit events (enforced or best effort).
	ObservationDelivery DeliveryGuarantee // ObservationDelivery specifies the delivery guarantees for observation events (enforced or best effort).
	SysEventsDelivery   DeliveryGuarantee // SysEventsDelivery specifies the delivery guarantees for system events (enforced or best effort).
	AuditEnabled        bool              // AuditEnabled specifies if audit events should be emitted.
	ObservationsEnabled bool              // ObservationsEnabled specifies if observation events should be emitted.
	SysEventsEnabled    bool              // SysEventsEnabled specifies if sysevents should be emitted.
	Sinks               []SinkConfig      // Sinks are all the configured sinks
}

EventerConfig supplies all the configuration needed to create/config an Eventer.

type GrantsInfo

type GrantsInfo struct {
	Grants []GrantsPair `json:"grants_pair,omitempty"`
}

type GrantsPair

type GrantsPair struct {
	Grant   string `json:"grant,omitempty"`
	ScopeId string `json:"scope_id,omitempty"`
}

type Id

type Id string

type Op

type Op string

type Option

type Option func(*options)

Option - how Options are passed as arguments.

func WithAuth

func WithAuth(a *Auth) Option

WithAuth allows an optional Auth

func WithDetails

func WithDetails(d map[string]interface{}) Option

WithDetails allows an optional map as details

func WithFlush

func WithFlush() Option

WithFlush allows an optional flush option.

func WithHeader

func WithHeader(d map[string]interface{}) Option

WithHeader allows an optional map as a header

func WithId

func WithId(id string) Option

WithId allows an optional Id

func WithNow

func WithNow(now time.Time) Option

WithNow allows an option time.Time to represent now.

func WithRequest

func WithRequest(r *Request) Option

WithRequest allows an optional request

func WithRequestInfo

func WithRequestInfo(i *RequestInfo) Option

WithRequestInfo allows an optional RequestInfo

func WithResponse

func WithResponse(r *Response) Option

WithResponse allows an optional response

type Request

type Request struct {
	Operation string        `json:"operation"` // std audit field
	Endpoint  string        `json:"endpoint"`  // std audit field
	Details   proto.Message `json:"details"`   // boundary field
}

type RequestInfo

type RequestInfo struct {
	Id       string `json:"id,omitempty"`
	Method   string `json:"method,omitempty"`
	Path     string `json:"path,omitempty"`
	PublicId string `json:"public_id,omitempty"`
}

RequestInfo defines the fields captured about a Boundary request.

func RequestInfoFromContext

func RequestInfoFromContext(ctx context.Context) (*RequestInfo, bool)

RequestInfoFromContext attempts to get the RequestInfo value from the context provided

func TestRequestInfo

func TestRequestInfo(t *testing.T) *RequestInfo

TestRequestInfo provides a test RequestInfo

type Response

type Response struct {
	StatusCode int           `json:"status_code,omitempty"` // std audit
	Details    proto.Message `json:"details,omitempty"`     // boundary field
}

type SinkConfig

type SinkConfig struct {
	Name           string        // Name defines a name for the sink.
	EventTypes     []Type        // EventTypes defines a list of event types that will be sent to the sink. See the docs for EventTypes for a list of accepted values.
	SinkType       SinkType      // SinkType defines the type of sink (StdoutSink or FileSink)
	Format         SinkFormat    // Format defines the format for the sink (JSONSinkFormat)
	Path           string        // Path defines the file path for the sink
	FileName       string        // FileName defines the file name for the sink
	RotateBytes    int           // RotateByes defines the number of bytes that should trigger rotation of a FileSink
	RotateDuration time.Duration // RotateDuration defines how often a FileSink should be rotated
	RotateMaxFiles int           // RotateMaxFiles defines how may historical rotated files should be kept for a FileSink
}

SinkConfig defines the configuration for a Eventer sink

type SinkFormat

type SinkFormat string // SinkFormat defines the formatting for a sink in a config file stanza (json)
const (
	JSONSinkFormat SinkFormat = "json" // JSONSinkFormat means the event is formatted as JSON
)

type SinkType

type SinkType string // SinkType defines the type of sink in a config stanza (file, stdout)
const (
	StdoutSink SinkType = "stdout" // StdoutSink is written to stdout
	FileSink   SinkType = "file"   // FileSink is written to a file
)

type TestConfig

type TestConfig struct {
	EventerConfig EventerConfig
	AllEvents     *os.File
	ErrorEvents   *os.File
}

func TestEventerConfig

func TestEventerConfig(t *testing.T, testName string, opt ...Option) TestConfig

TestEventerConfig creates a test config and registers a cleanup func for its test tmp files.

type Type

type Type string

Type represents the event's type

const (
	EveryType       Type = "*"           // EveryType represents every (all) types of events
	ObservationType Type = "observation" // ObservationType represents observation events
	AuditType       Type = "audit"       // AuditType represents audit events
	ErrorType       Type = "error"       // ErrorType represents error events
	SystemType      Type = "system"      // SysType represents system events
)

type UserInfo

type UserInfo struct {
	UserId        string `json:"id,omitempty"`
	AuthAccountId string `json:"auth_account_id,omitempty"`
}

UserInfo defines the fields captured about a user for a Boundary request.

Jump to

Keyboard shortcuts

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