hook

package
v0.0.0-...-2fb08ab Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2018 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
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

View 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

View Source
const (
	// EnvNamespace is the prefix used for passing arguments into the command
	// environment.
	EnvNamespace string = "HOOK_"
)

Variables

This section is empty.

Functions

func CheckIPWhitelist

func CheckIPWhitelist(remoteAddr string, ipRange string) (bool, error)

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

func CheckPayloadSignature(payload []byte, secret string, signature string) (string, error)

CheckPayloadSignature calculates and verifies SHA1 signature of the given payload

func CheckPayloadSignature256

func CheckPayloadSignature256(payload []byte, secret string, signature string) (string, error)

CheckPayloadSignature256 calculates and verifies SHA256 signature of the given payload

func ExtractParameterAsString

func ExtractParameterAsString(s string, params interface{}) (string, bool)

ExtractParameterAsString extracts value from interface{} as string based on the passed string

func GetParameter

func GetParameter(s string, params interface{}) (interface{}, bool)

GetParameter extracts interface{} value based on the passed string

func ReplaceParameter

func ReplaceParameter(s string, params interface{}, value interface{}) bool

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

func (AndRule) Evaluate

func (r AndRule) Evaluate(headers, query, payload *map[string]interface{}, body *[]byte, remoteAddr string) (bool, error)

Evaluate AndRule will return true if and only if all of 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

func (*Argument) Get

func (ha *Argument) Get(headers, query, payload *map[string]interface{}) (string, bool)

Get Argument method returns the value for the Argument's key name based on the Argument's source

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

type FileParameter struct {
	File    *os.File
	EnvName string
	Data    []byte
}

FileParameter describes a pass-file-to-command instance to be stored as file

type Header struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

Header is a structure containing header name and it's value

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

func (h *Hook) ParseJSONParameters(headers, query, payload *map[string]interface{}) []error

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

func (h *Hooks) Append(other *Hooks) error

Append appends hooks unless the new hooks contain a hook with an ID that already exists

func (*Hooks) LoadFromFile

func (h *Hooks) LoadFromFile(path string, asTemplate bool) error

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.

func (*Hooks) Match

func (h *Hooks) Match(id string) *Hook

Match iterates through Hooks and returns first one that matches the given ID, if no hook matches the given ID, nil is returned

type HooksFiles

type HooksFiles []string

HooksFiles is a slice of String

func (*HooksFiles) Set

func (h *HooksFiles) Set(value string) error

Set method appends new 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

func (MatchRule) Evaluate

func (r MatchRule) Evaluate(headers, query, payload *map[string]interface{}, body *[]byte, remoteAddr string) (bool, error)

Evaluate MatchRule will return based on the type

type NotRule

type NotRule Rules

NotRule will evaluate to true if any and only if the ChildRule evaluates to false

func (NotRule) Evaluate

func (r NotRule) Evaluate(headers, query, payload *map[string]interface{}, body *[]byte, remoteAddr string) (bool, error)

Evaluate NotRule will return true if and only if ChildRule evaluates to false

type OrRule

type OrRule []Rules

OrRule will evaluate to true if any of the ChildRules evaluate to true

func (OrRule) Evaluate

func (r OrRule) Evaluate(headers, query, payload *map[string]interface{}, body *[]byte, remoteAddr string) (bool, error)

Evaluate OrRule will return true if any of 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

func (Rules) Evaluate

func (r Rules) Evaluate(headers, query, payload *map[string]interface{}, body *[]byte, remoteAddr string) (bool, error)

Evaluate finds the first rule property that is not nil and returns the value it evaluates to

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

Jump to

Keyboard shortcuts

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