Documentation
¶
Index ¶
- Constants
- func CheckIPWhitelist(remoteAddr string, ipRange string) (bool, error)
- func CheckPayloadSignature(payload []byte, secret string, signature string) (string, error)
- func CheckPayloadSignature256(payload []byte, secret string, signature string) (string, error)
- func ExtractParameterAsString(s string, params interface{}) (string, bool)
- func GetParameter(s string, params interface{}) (interface{}, bool)
- func ReplaceParameter(s string, params interface{}, value interface{}) bool
- type AndRule
- type Argument
- type ArgumentError
- type FileParameter
- type Header
- type Hook
- func (h *Hook) ExtractCommandArguments(headers, query, payload *map[string]interface{}) ([]string, []error)
- func (h *Hook) ExtractCommandArgumentsForEnv(headers, query, payload *map[string]interface{}) ([]string, []error)
- func (h *Hook) ExtractCommandArgumentsForFile(headers, query, payload *map[string]interface{}) ([]FileParameter, []error)
- func (h *Hook) ParseJSONParameters(headers, query, payload *map[string]interface{}) []error
- type Hooks
- type HooksFiles
- type MatchRule
- type NotRule
- type OrRule
- type ParseError
- type ResponseHeaders
- type Rules
- type SignatureError
- type SourceError
Constants ¶
const ( SourceHeader string = "header" SourceQuery string = "url" SourceQueryAlias string = "query" SourcePayload string = "payload" 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" MatchHashSHA1 string = "payload-hash-sha1" MatchHashSHA256 string = "payload-hash-sha256" IPWhitelist string = "ip-whitelist" )
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 ExtractParameterAsString ¶
ExtractParameterAsString extracts value from interface{} as string based on the passed string
func GetParameter ¶
GetParameter extracts interface{} value based on the passed string
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"`
}
Hook type is a structure containing details for a single hook
func (*Hook) ExtractCommandArguments ¶
func (h *Hook) ExtractCommandArguments(headers, query, payload *map[string]interface{}) ([]string, []error)
ExtractCommandArguments creates a list of arguments, based on the PassArgumentsToCommand property that is ready to be used with exec.Command()
func (*Hook) ExtractCommandArgumentsForEnv ¶
func (h *Hook) ExtractCommandArgumentsForEnv(headers, query, payload *map[string]interface{}) ([]string, []error)
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(headers, query, payload *map[string]interface{}) ([]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 ParseError ¶
type ParseError struct {
Err error
}
ParseError describes an error parsing user input.
func (*ParseError) Error ¶
func (e *ParseError) Error() string
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
}
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