Documentation ¶
Index ¶
- Constants
- func CheckIPWhitelist(remoteAddr, ipRange string) (bool, error)
- func CheckPayloadSignature(payload []byte, secret, signature string) (string, error)
- func CheckPayloadSignature256(payload []byte, secret, signature string) (string, error)
- func CheckPayloadSignature512(payload []byte, secret, signature string) (string, error)
- func CheckScalrSignature(r *Request, signingKey string, checkDate bool) (bool, error)
- func ExtractCommaSeparatedValues(source, prefix string) []string
- func ExtractParameterAsString(s string, params interface{}) (string, error)
- func ExtractSignatures(source, prefix string) []string
- func GetParameter(s string, params interface{}) (interface{}, error)
- func IsParameterNodeError(err error) bool
- func IsSignatureError(err error) bool
- func ReplaceParameter(s string, params, value interface{}) bool
- func ValidateMAC(payload []byte, mac hash.Hash, signatures []string) (string, error)
- type AndRule
- type Argument
- type ArgumentError
- type FileParameter
- type Header
- type Hook
- type Hooks
- type HooksFiles
- type MatchRule
- type NotRule
- type OrRule
- type ParameterNodeError
- type ParseError
- type Request
- type ResponseHeaders
- type Rules
- type SignatureError
- type SourceError
Constants ¶
const ( SourceHeader string = "header" SourceQuery string = "url" SourceQueryAlias string = "query" SourcePayload string = "payload" SourceRawRequestBody string = "raw-request-body" SourceRequest string = "request" SourceString string = "string" SourceEntirePayload string = "entire-payload" SourceEntireQuery string = "entire-query" SourceEntireHeaders string = "entire-headers" )
Constants used to specify the parameter source
const ( MatchValue string = "value" MatchRegex string = "regex" MatchHMACSHA1 string = "payload-hmac-sha1" MatchHMACSHA256 string = "payload-hmac-sha256" MatchHMACSHA512 string = "payload-hmac-sha512" MatchHashSHA1 string = "payload-hash-sha1" MatchHashSHA256 string = "payload-hash-sha256" MatchHashSHA512 string = "payload-hash-sha512" IPWhitelist string = "ip-whitelist" ScalrSignature string = "scalr-signature" )
Constants for the MatchRule type
const ( // EnvNamespace is the prefix used for passing arguments into the command // environment. EnvNamespace string = "HOOK_" )
Variables ¶
This section is empty.
Functions ¶
func CheckIPWhitelist ¶
CheckIPWhitelist makes sure the provided remote address (of the form IP:port) falls within the provided IP range (in CIDR form or a single IP address).
func CheckPayloadSignature ¶
CheckPayloadSignature calculates and verifies SHA1 signature of the given payload
func CheckPayloadSignature256 ¶
CheckPayloadSignature256 calculates and verifies SHA256 signature of the given payload
func CheckPayloadSignature512 ¶
CheckPayloadSignature512 calculates and verifies SHA512 signature of the given payload
func CheckScalrSignature ¶
func ExtractCommaSeparatedValues ¶
ExtractCommaSeparatedValues will extract the values matching the key.
func ExtractParameterAsString ¶
ExtractParameterAsString extracts value from interface{} as string based on the passed string. Complex data types are rendered as JSON instead of the Go Stringer format.
func ExtractSignatures ¶
ExtractSignatures will extract all the signatures from the source.
func GetParameter ¶
GetParameter extracts interface{} value based on the passed string
func IsParameterNodeError ¶
IsParameterNodeError returns whether err is of type ParameterNodeError.
func IsSignatureError ¶
IsSignatureError returns whether err is of type SignatureError.
func ReplaceParameter ¶
ReplaceParameter replaces parameter value with the passed value in the passed map (please note you should pass pointer to the map, because we're modifying it) based on the passed string
Types ¶
type AndRule ¶
type AndRule []Rules
AndRule will evaluate to true if and only if all of the ChildRules evaluate to true
type Argument ¶
type Argument struct { Source string `json:"source,omitempty"` Name string `json:"name,omitempty"` EnvName string `json:"envname,omitempty"` Base64Decode bool `json:"base64decode,omitempty"` }
Argument type specifies the parameter key name and the source it should be extracted from
type ArgumentError ¶
type ArgumentError struct {
Argument Argument
}
ArgumentError describes an invalid argument passed to Hook.
func (*ArgumentError) Error ¶
func (e *ArgumentError) Error() string
type FileParameter ¶
FileParameter describes a pass-file-to-command instance to be stored as file
type Hook ¶
type Hook struct { ID string `json:"id,omitempty"` ExecuteCommand string `json:"execute-command,omitempty"` CommandWorkingDirectory string `json:"command-working-directory,omitempty"` ResponseMessage string `json:"response-message,omitempty"` ResponseHeaders ResponseHeaders `json:"response-headers,omitempty"` CaptureCommandOutput bool `json:"include-command-output-in-response,omitempty"` CaptureCommandOutputOnError bool `json:"include-command-output-in-response-on-error,omitempty"` PassEnvironmentToCommand []Argument `json:"pass-environment-to-command,omitempty"` PassArgumentsToCommand []Argument `json:"pass-arguments-to-command,omitempty"` PassFileToCommand []Argument `json:"pass-file-to-command,omitempty"` JSONStringParameters []Argument `json:"parse-parameters-as-json,omitempty"` TriggerRule *Rules `json:"trigger-rule,omitempty"` TriggerRuleMismatchHttpResponseCode int `json:"trigger-rule-mismatch-http-response-code,omitempty"` TriggerSignatureSoftFailures bool `json:"trigger-signature-soft-failures,omitempty"` IncomingPayloadContentType string `json:"incoming-payload-content-type,omitempty"` SuccessHttpResponseCode int `json:"success-http-response-code,omitempty"` HTTPMethods []string `json:"http-methods"` }
Hook type is a structure containing details for a single hook
func (*Hook) ExtractCommandArguments ¶
ExtractCommandArguments creates a list of arguments, based on the PassArgumentsToCommand property that is ready to be used with exec.Command()
func (*Hook) ExtractCommandArgumentsForEnv ¶
ExtractCommandArgumentsForEnv creates a list of arguments in key=value format, based on the PassEnvironmentToCommand property that is ready to be used with exec.Command().
func (*Hook) ExtractCommandArgumentsForFile ¶
func (h *Hook) ExtractCommandArgumentsForFile(r *Request) ([]FileParameter, []error)
ExtractCommandArgumentsForFile creates a list of arguments in key=value format, based on the PassFileToCommand property that is ready to be used with exec.Command().
func (*Hook) ParseJSONParameters ¶
ParseJSONParameters decodes specified arguments to JSON objects and replaces the string with the newly created object
type Hooks ¶
type Hooks []Hook
Hooks is an array of Hook objects
func (*Hooks) Append ¶
Append appends hooks unless the new hooks contain a hook with an ID that already exists
func (*Hooks) LoadFromFile ¶
LoadFromFile attempts to load hooks from the specified file, which can be either JSON or YAML. The asTemplate parameter causes the file contents to be parsed as a Go text/template prior to unmarshalling.
type HooksFiles ¶
type HooksFiles []string
HooksFiles is a slice of String
func (*HooksFiles) String ¶
func (h *HooksFiles) String() string
type MatchRule ¶
type MatchRule struct { Type string `json:"type,omitempty"` Regex string `json:"regex,omitempty"` Secret string `json:"secret,omitempty"` Value string `json:"value,omitempty"` Parameter Argument `json:"parameter,omitempty"` IPRange string `json:"ip-range,omitempty"` }
MatchRule will evaluate to true based on the type
type NotRule ¶
type NotRule Rules
NotRule will evaluate to true if any and only if the ChildRule evaluates to false
type OrRule ¶
type OrRule []Rules
OrRule will evaluate to true if any of the ChildRules evaluate to true
type ParameterNodeError ¶
type ParameterNodeError struct {
// contains filtered or unexported fields
}
ParameterNodeError describes an error walking a parameter node.
func (*ParameterNodeError) Error ¶
func (e *ParameterNodeError) Error() string
type ParseError ¶
type ParseError struct {
Err error
}
ParseError describes an error parsing user input.
func (*ParseError) Error ¶
func (e *ParseError) Error() string
type Request ¶
type Request struct { // The request ID set by the RequestID middleware. ID string // The Content-Type of the request. ContentType string // The raw request body. Body []byte // Headers is a map of the parsed headers. Headers map[string]interface{} // Query is a map of the parsed URL query values. Query map[string]interface{} // Payload is a map of the parsed payload. Payload map[string]interface{} // The underlying HTTP request. RawRequest *http.Request // Treat signature errors as simple validate failures. AllowSignatureErrors bool }
Request represents a webhook request.
func (*Request) ParseFormPayload ¶
func (*Request) ParseHeaders ¶
func (*Request) ParseJSONPayload ¶
func (*Request) ParseQuery ¶
func (*Request) ParseXMLPayload ¶
type ResponseHeaders ¶
type ResponseHeaders []Header
ResponseHeaders is a slice of Header objects
func (*ResponseHeaders) Set ¶
func (h *ResponseHeaders) Set(value string) error
Set method appends new Header object from header=value notation
func (*ResponseHeaders) String ¶
func (h *ResponseHeaders) String() string
type Rules ¶
type Rules struct { And *AndRule `json:"and,omitempty"` Or *OrRule `json:"or,omitempty"` Not *NotRule `json:"not,omitempty"` Match *MatchRule `json:"match,omitempty"` }
Rules is a structure that contains one of the valid rule types
type SignatureError ¶
type SignatureError struct { Signature string Signatures []string // contains filtered or unexported fields }
SignatureError describes an invalid payload signature passed to Hook.
func (*SignatureError) Error ¶
func (e *SignatureError) Error() string
type SourceError ¶
type SourceError struct {
Argument Argument
}
SourceError describes an invalid source passed to Hook.
func (*SourceError) Error ¶
func (e *SourceError) Error() string