hook

package
v0.0.0-...-7bb6808 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2024 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

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

View 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

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, 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, signature string) (string, error)

CheckPayloadSignature calculates and verifies SHA1 signature of the given payload

func CheckPayloadSignature256

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

CheckPayloadSignature256 calculates and verifies SHA256 signature of the given payload

func CheckPayloadSignature512

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

CheckPayloadSignature512 calculates and verifies SHA512 signature of the given payload

func CheckScalrSignature

func CheckScalrSignature(r *Request, signingKey string, checkDate bool) (bool, error)

func ExtractCommaSeparatedValues

func ExtractCommaSeparatedValues(source, prefix string) []string

ExtractCommaSeparatedValues will extract the values matching the key.

func ExtractParameterAsString

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

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

func ExtractSignatures(source, prefix string) []string

ExtractSignatures will extract all the signatures from the source.

func GetParameter

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

GetParameter extracts interface{} value based on the passed string

func IsParameterNodeError

func IsParameterNodeError(err error) bool

IsParameterNodeError returns whether err is of type ParameterNodeError.

func IsSignatureError

func IsSignatureError(err error) bool

IsSignatureError returns whether err is of type SignatureError.

func ReplaceParameter

func ReplaceParameter(s string, params, 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

func ValidateMAC

func ValidateMAC(payload []byte, mac hash.Hash, signatures []string) (string, error)

ValidateMAC will verify that the expected mac for the given hash will match the one provided.

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(req *Request) (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(r *Request) (string, error)

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

func (h *Hook) ExtractCommandArguments(r *Request) ([]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(r *Request) ([]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(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

func (h *Hook) ParseJSONParameters(r *Request) []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(req *Request) (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(req *Request) (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(req *Request) (bool, error)

Evaluate OrRule will return true if any of 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 (r *Request) ParseFormPayload() error

func (*Request) ParseHeaders

func (r *Request) ParseHeaders(headers map[string][]string)

func (*Request) ParseJSONPayload

func (r *Request) ParseJSONPayload() error

func (*Request) ParseQuery

func (r *Request) ParseQuery(query map[string][]string)

func (*Request) ParseXMLPayload

func (r *Request) ParseXMLPayload() error

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(req *Request) (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
	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

Jump to

Keyboard shortcuts

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