hook

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

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

Go to latest
Published: Jul 23, 2015 License: MIT Imports: 11 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

Variables

This section is empty.

Functions

func CheckPayloadSignature

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

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

Evaluate AndRule will return true if and only if all of ChildRules evaluate to true

type Argument

type Argument struct {
	Source string `json:"source"`
	Name   string `json:"name"`
}

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 CommandStatusResponse

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

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

type Hook

type Hook struct {
	ID                      string     `json:"id"`
	ExecuteCommand          string     `json:"execute-command"`
	CommandWorkingDirectory string     `json:"command-working-directory"`
	ResponseMessage         string     `json:"response-message"`
	CaptureCommandOutput    bool       `json:"include-command-output-in-response"`
	PassArgumentsToCommand  []Argument `json:"pass-arguments-to-command"`
	JSONStringParameters    []Argument `json:"parse-parameters-as-json"`
	TriggerRule             *Rules     `json:"trigger-rule"`
}

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

ExtractCommandArguments creates a list of arguments, based on the PassArgumentsToCommand property that is ready to be used with exec.Command()

func (*Hook) ParseJSONParameters

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

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"`
	Regex     string   `json:"regex"`
	Secret    string   `json:"secret"`
	Value     string   `json:"value"`
	Parameter Argument `json:"parameter"`
}

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

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

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

Evaluate OrRule will return true if any of ChildRules evaluate to true

type Rules

type Rules struct {
	And   *AndRule   `json:"and"`
	Or    *OrRule    `json:"or"`
	Not   *NotRule   `json:"not"`
	Match *MatchRule `json:"match"`
}

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

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

Jump to

Keyboard shortcuts

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