Documentation ¶
Index ¶
- Constants
- Variables
- func ParseFormData(reader io.Reader) (map[string][]string, error)
- func PrepareTriggeredRulesForReport(triggeredRules []*DataCollectionRule) []proxy.ReportDataCollectionRule
- func RFCListener(_ context.Context, e events.Event) error
- func ToBytes(x interface{}) ([]byte, error)
- func ToHash(j interface{}) string
- func ToSha(j interface{}) string
- type APIEvent
- type APIEventConfig
- type BodiesEvent
- type BodyParsingProvider
- type BodyReadCloser
- type ConnectEvent
- func (ae *ConnectEvent) Config() *APIEventConfig
- func (re ConnectEvent) Request() *http.Request
- func (ae *ConnectEvent) SetConfig(value *APIEventConfig) APIEvent
- func (ae *ConnectEvent) SetTriggeredDataCollectionRules(rules []*DataCollectionRule) APIEvent
- func (re ConnectEvent) Topic() events.Topic
- func (ae *ConnectEvent) TriggeredDataCollectionRules() []*DataCollectionRule
- type ContextKey
- type DCRProvider
- type DataCollectionRule
- type DataCollectionRuleDescription
- type DynamicConfigDescription
- type FieldDescriptor
- func (*FieldDescriptor) Descriptor() ([]byte, []int)deprecated
- func (x *FieldDescriptor) GetHash() *ShapeDescriptor
- func (x *FieldDescriptor) GetKey() string
- func (*FieldDescriptor) ProtoMessage()
- func (x *FieldDescriptor) ProtoReflect() protoreflect.Message
- func (x *FieldDescriptor) Reset()
- func (x *FieldDescriptor) String() string
- type LogLevel
- type ProxyProvider
- type ReportEvent
- func (ae ReportEvent) Config() *APIEventConfig
- func (ae ReportEvent) SetConfig(value *APIEventConfig) APIEvent
- func (ae ReportEvent) SetTriggeredDataCollectionRules(rules []*DataCollectionRule) APIEvent
- func (ReportEvent) Topic() events.Topic
- func (ae ReportEvent) TriggeredDataCollectionRules() []*DataCollectionRule
- type RequestEvent
- func (ae *RequestEvent) Config() *APIEventConfig
- func (ae *RequestEvent) SetConfig(value *APIEventConfig) APIEvent
- func (ae *RequestEvent) SetTriggeredDataCollectionRules(rules []*DataCollectionRule) APIEvent
- func (re RequestEvent) Topic() events.Topic
- func (ae *RequestEvent) TriggeredDataCollectionRules() []*DataCollectionRule
- type ResponseEvent
- func (ae *ResponseEvent) Config() *APIEventConfig
- func (ae *ResponseEvent) SetConfig(value *APIEventConfig) APIEvent
- func (ae *ResponseEvent) SetTriggeredDataCollectionRules(rules []*DataCollectionRule) APIEvent
- func (ResponseEvent) Topic() events.Topic
- func (ae *ResponseEvent) TriggeredDataCollectionRules() []*DataCollectionRule
- type RoundTripper
- type SanitizationProvider
- func (p SanitizationProvider) BodySanitizer(k interface{}, v *interface{}, accu *interface{}) error
- func (p SanitizationProvider) Listeners(e events.Event) []events.Listener
- func (p SanitizationProvider) SanitizeQueryAndPaths(_ context.Context, e events.Event) error
- func (p SanitizationProvider) SanitizeRequestBody(_ context.Context, e events.Event) error
- func (p SanitizationProvider) SanitizeRequestHeaders(_ context.Context, e events.Event) error
- func (p SanitizationProvider) SanitizeResponseBody(_ context.Context, e events.Event) error
- func (p SanitizationProvider) SanitizeResponseHeaders(_ context.Context, e events.Event) error
- type ShapeDescriptor
- func (*ShapeDescriptor) Descriptor() ([]byte, []int)deprecated
- func (x *ShapeDescriptor) GetFields() []*FieldDescriptor
- func (x *ShapeDescriptor) GetItems() []*ShapeDescriptor
- func (x *ShapeDescriptor) GetRules() []string
- func (x *ShapeDescriptor) GetType() ShapeDescriptor_PrimitiveType
- func (*ShapeDescriptor) ProtoMessage()
- func (x *ShapeDescriptor) ProtoReflect() protoreflect.Message
- func (x *ShapeDescriptor) Reset()
- func (x *ShapeDescriptor) String() string
- type ShapeDescriptor_PrimitiveType
- func (ShapeDescriptor_PrimitiveType) Descriptor() protoreflect.EnumDescriptor
- func (x ShapeDescriptor_PrimitiveType) Enum() *ShapeDescriptor_PrimitiveType
- func (ShapeDescriptor_PrimitiveType) EnumDescriptor() ([]byte, []int)deprecated
- func (x ShapeDescriptor_PrimitiveType) Number() protoreflect.EnumNumber
- func (x ShapeDescriptor_PrimitiveType) String() string
- func (ShapeDescriptor_PrimitiveType) Type() protoreflect.EnumType
- type WalkFn
- type Walker
Constants ¶
const ( // TopicConnect is the earliest event triggered in an intercepted API. // It is used to validate the endpoint URL, regardless of the Request which // will be sent to it. TopicConnect events.Topic = "connect" // TopicRequest is the second event triggered in an intercepted API. // It is used to validate the Request itself, as well as its context. TopicRequest events.Topic = "request" // TopicResponse is the third event triggered in an intercepted API. // It is used to react to the response headers and possibly start of resBody // being received. Note that at this point, there is no guarantee that either // the Request or Response bodies are actually entirely available, due to // HTTP advanced features like request/response interleaving. It is not // triggered if the round-trip returns an error, as the associated response // is not guaranteed to be well-formed. TopicResponse events.Topic = "response" // TopicBodies is the fourth and last event triggered in an intercepted API. // It is used once the bodies on both Request and Response have been closed // by the API client. It does NOT mean that these bodies are necessarily // complete, as a client may have closed a request early. TopicBodies events.Topic = "bodies" // TopicReport is the event used to request transmission of a ReportLog to // the logs platform. Unlike its four siblings, it can be triggered at any // stage of the API call lifecycle. TopicReport events.Topic = "report_log" )
const ( // BodyTooLong is the replacement string for bodies beyond MaximumBodySize. BodyTooLong = `(omitted due to size)` // BodyIsBinary is the replacement string for unparseable bodies. BodyIsBinary = `(not showing binary data)` // BodyUndecodable is the replacement string for bodies which were expected to be parsable but failed decoding. BodyUndecodable = `(could not decode data)` // MaximumBodySize is the largest resBody size to store whole. MaximumBodySize = 1 << 20 )
const Filtered = `[FILTERED]`
Filtered is a well-known string replacing filtered-out content.
Variables ¶
var ( ShapeDescriptor_PrimitiveType_name = map[int32]string{ 0: "OBJECT", 1: "ARRAY", 2: "STRING", 3: "NUMBER", 4: "BOOLEAN", 5: "NULL", } ShapeDescriptor_PrimitiveType_value = map[string]int32{ "OBJECT": 0, "ARRAY": 1, "STRING": 2, "NUMBER": 3, "BOOLEAN": 4, "NULL": 5, } )
Enum value maps for ShapeDescriptor_PrimitiveType.
var DefaultSensitiveData = regexp.MustCompile("(?i)[a-z0-9]{1}[a-z0-9.!#$%&’*+=?^_\"{|}~-]+@[a-z0-9-]+(?:\\.[a-z0-9-]+)*|(?:\\d[ -]*?){13,16}")
DefaultSensitiveData is the expression used for sensitive data if no other value is set.
var DefaultSensitiveKeys = regexp.MustCompile(`(?i)^(authorization|password|secret|passwd|api.?key|access.?token|auth.?token|credentials|mysql_pwd|stripetoken|card.?number.?|secret|client.?id|client.?secret)$`)
DefaultSensitiveKeys is the expression used for sensitive keys if no other value is set.
var File_shape_hash_proto protoreflect.FileDescriptor
var FormContentType = regexp.MustCompile(`(?i)x-www-form-urlencoded`)
FormContentType is a regexp definint the content types to handle as traditional web forms.
var JSONContentType = regexp.MustCompile(`(?i)json`)
JSONContentType is a regexp defining the content types to handle as JSON.
var ParsableContentType = regexp.MustCompile(`(?i)(json|text|xml|x-www-form-urlencoded)`)
ParsableContentType is a regexp defining the types to attempt to parse.
var StringContentType = regexp.MustCompile(`(?i)(text|xml)`)
StringContentType is a regexp defininig the types to return as plain strings.
Functions ¶
func ParseFormData ¶
ParseFormData parses form data
func PrepareTriggeredRulesForReport ¶
func PrepareTriggeredRulesForReport(triggeredRules []*DataCollectionRule) []proxy.ReportDataCollectionRule
PrepareTriggeredRulesForReport translates DataCollectionRule objects representing triggered rules into the format used for reporting
func RFCListener ¶
RFCListener validates the destination URL under RFC793, RFC1384, RFC1738 and RFC3986 before entering the standard Bearer multistage API wrapping.
It is hard-coded in the round-tripper to avoid its being disabled.
Types ¶
type APIEvent ¶
type APIEvent interface { events.Event Config() *APIEventConfig SetConfig(value *APIEventConfig) APIEvent TriggeredDataCollectionRules() []*DataCollectionRule SetTriggeredDataCollectionRules(rules []*DataCollectionRule) APIEvent }
APIEvent is the type common to all API call lifecycle events.
type APIEventConfig ¶
APIEventConfig represents configuration values derived from all triggered DataCollectionRule objects.
type BodiesEvent ¶
type BodiesEvent struct {
RequestBody, ResponseBody interface{}
RequestSha, ResponseSha string
// contains filtered or unexported fields
}
BodiesEvent is the type of events dispatched at the TopicBodies stage.
func (*BodiesEvent) Config ¶
func (ae *BodiesEvent) Config() *APIEventConfig
func (*BodiesEvent) SetConfig ¶
func (ae *BodiesEvent) SetConfig(value *APIEventConfig) APIEvent
func (*BodiesEvent) SetTriggeredDataCollectionRules ¶
func (ae *BodiesEvent) SetTriggeredDataCollectionRules(rules []*DataCollectionRule) APIEvent
func (*BodiesEvent) TriggeredDataCollectionRules ¶
func (ae *BodiesEvent) TriggeredDataCollectionRules() []*DataCollectionRule
type BodyParsingProvider ¶
type BodyParsingProvider struct{}
BodyParsingProvider is an events.Listener provider returning listeners performing data collection, hashing, and sanitization on request/reponse bodies.
func (BodyParsingProvider) Listeners ¶
func (p BodyParsingProvider) Listeners(e events.Event) (l []events.Listener)
Listeners implements events.ListenerProvider.
func (BodyParsingProvider) RequestBodyParser ¶
RequestBodyParser is an events.Listener performing eager resBody loading on API requests, to perform sanitization and bandwidth reduction.
func (BodyParsingProvider) ResponseBodyParser ¶
ResponseBodyParser is an events.Listener performing eager resBody loading on API responses, to perform sanitization and bandwidth reduction.
type BodyReadCloser ¶
type BodyReadCloser struct {
// contains filtered or unexported fields
}
BodyReadCloser wraps a io.ReadCloser to give access to the first peekSize bytes without interfering with the normal behaviour
func NewBodyReadCloser ¶
func NewBodyReadCloser(readCloser io.ReadCloser, peekSize int) *BodyReadCloser
NewBodyReadCloser constructs a BodyReadCloser wrapper
func (*BodyReadCloser) Close ¶
func (r *BodyReadCloser) Close() error
Close closes the underlying io.ReadCloser
func (*BodyReadCloser) Peek ¶
func (r *BodyReadCloser) Peek() ([]byte, error)
Peek returns the result of reading the first peek bytes block
type ConnectEvent ¶
type ConnectEvent struct { // Host is the host to which the request is sent. It may be an IPv6 braced address. Host string // Port is the TCP port number, in the uint16 range by RFC793. Port uint16 // Scheme, also known as "protocol", is the first part of RFC3986 URL syntax. Scheme string // contains filtered or unexported fields }
ConnectEvent is the type of events dispatched at the TopicConnect stage.
Its Data() is a URL. Recommended use is to set the URL
func NewConnectEvent ¶
func NewConnectEvent(url *url.URL) *ConnectEvent
NewConnectEvent builds a ConnectEvent for a url.URL.
func (*ConnectEvent) Config ¶
func (ae *ConnectEvent) Config() *APIEventConfig
func (ConnectEvent) Request ¶
func (re ConnectEvent) Request() *http.Request
Request overrides the events.EventBase.Request method, building an on-the-fly request from the event fields. It accepts building partial URLs, which may be invalid.
func (*ConnectEvent) SetConfig ¶
func (ae *ConnectEvent) SetConfig(value *APIEventConfig) APIEvent
func (*ConnectEvent) SetTriggeredDataCollectionRules ¶
func (ae *ConnectEvent) SetTriggeredDataCollectionRules(rules []*DataCollectionRule) APIEvent
func (ConnectEvent) Topic ¶
func (re ConnectEvent) Topic() events.Topic
Topic is part of the Event interface.
func (*ConnectEvent) TriggeredDataCollectionRules ¶
func (ae *ConnectEvent) TriggeredDataCollectionRules() []*DataCollectionRule
type ContextKey ¶
type ContextKey string
ContextKey is the type to use for any key added to the context by this package.
type DCRProvider ¶
type DCRProvider struct {
DCRs []*DataCollectionRule
}
DCRProvider is an events.Listener provider returning listeners based on the active data collection rules.
type DataCollectionRule ¶
type DataCollectionRule struct { filters.Filter *LogLevel IsActive *bool FilterHash string Params map[string]interface{} Signature string }
DataCollectionRule represents a data collection rule.
Inactive rules descriptions generate nil *DataCollectionRule values.
func NewDCRFromDescription ¶
func NewDCRFromDescription(filterMap filters.FilterMap, d DataCollectionRuleDescription) *DataCollectionRule
NewDCRFromDescription creates a DataCollectionRule from a DataCollectionRuleDescription and a valid filters.FilterMap.
type DataCollectionRuleDescription ¶
type DataCollectionRuleDescription struct { FilterHash string Params map[string]interface{} Config DynamicConfigDescription Signature string }
DataCollectionRuleDescription is a serialization-friendly description for a data collection rule.
func (DataCollectionRuleDescription) String ¶
func (d DataCollectionRuleDescription) String() string
type DynamicConfigDescription ¶
type DynamicConfigDescription struct { LogLevel *string // ALL, RESTRICTED, or DETECTED. Active *bool }
DynamicConfigDescription provides a serialization-friendy description of DynamicConfig.
type FieldDescriptor ¶
type FieldDescriptor struct { Hash *ShapeDescriptor `protobuf:"bytes,1,opt,name=hash,proto3" json:"hash,omitempty"` Key string `protobuf:"bytes,2,opt,name=key,proto3" json:"key,omitempty"` // contains filtered or unexported fields }
func (*FieldDescriptor) Descriptor
deprecated
func (*FieldDescriptor) Descriptor() ([]byte, []int)
Deprecated: Use FieldDescriptor.ProtoReflect.Descriptor instead.
func (*FieldDescriptor) GetHash ¶
func (x *FieldDescriptor) GetHash() *ShapeDescriptor
func (*FieldDescriptor) GetKey ¶
func (x *FieldDescriptor) GetKey() string
func (*FieldDescriptor) ProtoMessage ¶
func (*FieldDescriptor) ProtoMessage()
func (*FieldDescriptor) ProtoReflect ¶
func (x *FieldDescriptor) ProtoReflect() protoreflect.Message
func (*FieldDescriptor) Reset ¶
func (x *FieldDescriptor) Reset()
func (*FieldDescriptor) String ¶
func (x *FieldDescriptor) String() string
type LogLevel ¶
type LogLevel int
LogLevel represents the log levels defined by the Bearer platform.
const ( // Detected specifies that the agent should send log level and connection data only. Detected LogLevel = iota - 1 // Restricted specifies that the agent should send common data and all available stage data, // excluding request and response headers and bodies. Restricted // All specifies that the agent should send common data and all available stage data. All )
func LogLevelFromInt ¶
LogLevelFromInt converts any int to a valid LogLevel, adjusting non-valid values to the default LogLevel: Restricted.
func LogLevelFromString ¶
LogLevelFromString builds a LogLevel from a string, defaulting to Restricted for all invalid strings.
type ProxyProvider ¶
ProxyProvider is an events.ListenerProvider returning a proxy listener.
type ReportEvent ¶
type ReportEvent struct { *BodiesEvent proxy.Stage T0, T1 time.Time }
ReportEvent is emitted to publish a call proxy.ReportLog.
func NewReportEvent ¶
func NewReportEvent(stage proxy.Stage, err error) *ReportEvent
NewReportEvent builds a ReportEvent, empty but for stage, and error.
func (ReportEvent) Config ¶
func (ae ReportEvent) Config() *APIEventConfig
func (ReportEvent) SetConfig ¶
func (ae ReportEvent) SetConfig(value *APIEventConfig) APIEvent
func (ReportEvent) SetTriggeredDataCollectionRules ¶
func (ae ReportEvent) SetTriggeredDataCollectionRules(rules []*DataCollectionRule) APIEvent
func (ReportEvent) Topic ¶
func (ReportEvent) Topic() events.Topic
Topic is part of the Event interface.
func (ReportEvent) TriggeredDataCollectionRules ¶
func (ae ReportEvent) TriggeredDataCollectionRules() []*DataCollectionRule
type RequestEvent ¶
type RequestEvent struct {
// contains filtered or unexported fields
}
RequestEvent is the type of events dispatched at the TopicRequest stages.
func (*RequestEvent) Config ¶
func (ae *RequestEvent) Config() *APIEventConfig
func (*RequestEvent) SetConfig ¶
func (ae *RequestEvent) SetConfig(value *APIEventConfig) APIEvent
func (*RequestEvent) SetTriggeredDataCollectionRules ¶
func (ae *RequestEvent) SetTriggeredDataCollectionRules(rules []*DataCollectionRule) APIEvent
func (RequestEvent) Topic ¶
func (re RequestEvent) Topic() events.Topic
Topic is part of the Event interface.
func (*RequestEvent) TriggeredDataCollectionRules ¶
func (ae *RequestEvent) TriggeredDataCollectionRules() []*DataCollectionRule
type ResponseEvent ¶
type ResponseEvent struct {
// contains filtered or unexported fields
}
ResponseEvent is the type of events dispatched at the TopicResponse stage.
func (*ResponseEvent) Config ¶
func (ae *ResponseEvent) Config() *APIEventConfig
func (*ResponseEvent) SetConfig ¶
func (ae *ResponseEvent) SetConfig(value *APIEventConfig) APIEvent
func (*ResponseEvent) SetTriggeredDataCollectionRules ¶
func (ae *ResponseEvent) SetTriggeredDataCollectionRules(rules []*DataCollectionRule) APIEvent
func (ResponseEvent) Topic ¶
func (ResponseEvent) Topic() events.Topic
Topic is part of the Event interface.
func (*ResponseEvent) TriggeredDataCollectionRules ¶
func (ae *ResponseEvent) TriggeredDataCollectionRules() []*DataCollectionRule
type RoundTripper ¶
type RoundTripper struct { events.Dispatcher Underlying http.RoundTripper }
RoundTripper is the instrumented implementation of http.RoundTripper.
It triggers events for the TopicConnect, TopicRequest, and TopicResponse stages.
type SanitizationProvider ¶
type SanitizationProvider struct { SensitiveKeys []*regexp.Regexp SensitiveRegexps []*regexp.Regexp }
SanitizationProvider is an events.Listener provider returning listeners based on the sensitive keys and regexps.
func (SanitizationProvider) BodySanitizer ¶
func (p SanitizationProvider) BodySanitizer(k interface{}, v *interface{}, accu *interface{}) error
BodySanitizer applies sanitization rules to data.
func (SanitizationProvider) Listeners ¶
func (p SanitizationProvider) Listeners(e events.Event) []events.Listener
Listeners implements the events.ListenerProvider interface.
func (SanitizationProvider) SanitizeQueryAndPaths ¶
SanitizeQueryAndPaths sanitizes the URL query parameters and paths in both the original request and the request present in the response, which may or may not be the same.
func (SanitizationProvider) SanitizeRequestBody ¶
SanitizeRequestBody sanitized the Request resBody in a ReportEvent.
func (SanitizationProvider) SanitizeRequestHeaders ¶
SanitizeRequestHeaders sanitizes Request headers and trailers.
func (SanitizationProvider) SanitizeResponseBody ¶
SanitizeResponseBody sanitizes the Response resBody in a ReportEvent.
func (SanitizationProvider) SanitizeResponseHeaders ¶
SanitizeResponseHeaders sanitizes Response headers and trailers.
type ShapeDescriptor ¶
type ShapeDescriptor struct { // Order in schema is used for JSON, while numbers are used for protobuf. Fields []*FieldDescriptor `protobuf:"bytes,4,rep,name=fields,proto3" json:"fields,omitempty"` Items []*ShapeDescriptor `protobuf:"bytes,2,rep,name=items,proto3" json:"items,omitempty"` Rules []string `protobuf:"bytes,3,rep,name=rules,proto3" json:"rules,omitempty"` Type ShapeDescriptor_PrimitiveType `protobuf:"varint,1,opt,name=type,proto3,enum=bearer_agent_shape_hash.ShapeDescriptor_PrimitiveType" json:"type,omitempty"` // contains filtered or unexported fields }
func NewShapeDescriptor ¶
func NewShapeDescriptor(typ ShapeDescriptor_PrimitiveType, fields []*FieldDescriptor, items []*ShapeDescriptor) *ShapeDescriptor
NewShapeDescriptor builds a new ShapeDescriptor from its fields.
func (*ShapeDescriptor) Descriptor
deprecated
func (*ShapeDescriptor) Descriptor() ([]byte, []int)
Deprecated: Use ShapeDescriptor.ProtoReflect.Descriptor instead.
func (*ShapeDescriptor) GetFields ¶
func (x *ShapeDescriptor) GetFields() []*FieldDescriptor
func (*ShapeDescriptor) GetItems ¶
func (x *ShapeDescriptor) GetItems() []*ShapeDescriptor
func (*ShapeDescriptor) GetRules ¶
func (x *ShapeDescriptor) GetRules() []string
func (*ShapeDescriptor) GetType ¶
func (x *ShapeDescriptor) GetType() ShapeDescriptor_PrimitiveType
func (*ShapeDescriptor) ProtoMessage ¶
func (*ShapeDescriptor) ProtoMessage()
func (*ShapeDescriptor) ProtoReflect ¶
func (x *ShapeDescriptor) ProtoReflect() protoreflect.Message
func (*ShapeDescriptor) Reset ¶
func (x *ShapeDescriptor) Reset()
func (*ShapeDescriptor) String ¶
func (x *ShapeDescriptor) String() string
type ShapeDescriptor_PrimitiveType ¶
type ShapeDescriptor_PrimitiveType int32
const ( ShapeDescriptor_OBJECT ShapeDescriptor_PrimitiveType = 0 ShapeDescriptor_ARRAY ShapeDescriptor_PrimitiveType = 1 ShapeDescriptor_STRING ShapeDescriptor_PrimitiveType = 2 ShapeDescriptor_NUMBER ShapeDescriptor_PrimitiveType = 3 ShapeDescriptor_BOOLEAN ShapeDescriptor_PrimitiveType = 4 ShapeDescriptor_NULL ShapeDescriptor_PrimitiveType = 5 )
func (ShapeDescriptor_PrimitiveType) Descriptor ¶
func (ShapeDescriptor_PrimitiveType) Descriptor() protoreflect.EnumDescriptor
func (ShapeDescriptor_PrimitiveType) Enum ¶
func (x ShapeDescriptor_PrimitiveType) Enum() *ShapeDescriptor_PrimitiveType
func (ShapeDescriptor_PrimitiveType) EnumDescriptor
deprecated
func (ShapeDescriptor_PrimitiveType) EnumDescriptor() ([]byte, []int)
Deprecated: Use ShapeDescriptor_PrimitiveType.Descriptor instead.
func (ShapeDescriptor_PrimitiveType) Number ¶
func (x ShapeDescriptor_PrimitiveType) Number() protoreflect.EnumNumber
func (ShapeDescriptor_PrimitiveType) String ¶
func (x ShapeDescriptor_PrimitiveType) String() string
func (ShapeDescriptor_PrimitiveType) Type ¶
func (ShapeDescriptor_PrimitiveType) Type() protoreflect.EnumType
type WalkFn ¶
type WalkFn func(ik interface{}, iv *interface{}, accu *interface{}) error
WalkFn is the type for visitor functions used with a Walker.