hook

package
v0.0.0-...-80aa980 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2016 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SourceHeader        string = "header"
	SourceQuery         string = "url"
	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"
)

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 CheckPayloadSignature

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

CheckPayloadSignature calculates and verifies SHA1 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) (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"`
}

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 CommandStatusResponse

type CommandStatusResponse struct {
	ResponseMessage string `json:"message,omitempty"`
	Output          string `json:"output,omitempty"`
	Error           string `json:"error,omitempty"`
}

CommandStatusResponse type encapsulates the executed command exit code, message, stdout and stderr

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"`
	CaptureCommandOutput     bool       `json:"include-command-output-in-response,omitempty"`
	PassEnvironmentToCommand []Argument `json:"pass-environment-to-command,omitempty"`
	PassArgumentsToCommand   []Argument `json:"pass-arguments-to-command,omitempty"`
	JSONStringParameters     []Argument `json:"parse-parameters-as-json,omitempty"`
	TriggerRule              *Rules     `json:"trigger-rule,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) 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) LoadFromFile

func (h *Hooks) LoadFromFile(path string) error

LoadFromFile attempts to load hooks from specified JSON file

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

func (*Hooks) MatchAll

func (h *Hooks) MatchAll(id string) []*Hook

MatchAll iterates through Hooks and returns all of the hooks that match the given ID, if no hook matches the given ID, nil is returned

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"`
}

MatchRule will evaluate to true based on the type

func (MatchRule) Evaluate

func (r MatchRule) Evaluate(headers, query, payload *map[string]interface{}, body *[]byte) (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) (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) (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 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) (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