captainhook

package module
v0.0.0-...-42569ab Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2020 License: MPL-2.0 Imports: 10 Imported by: 0

README

CaptainHook

Go Test Go Build

Cloud based awk, transform and glue webhooks and api's together.

.\captainhook help
serve: Start the CaptainHook application server.
  -configPath string
        YAML file to configure the service with endpoints. (default "config.yml")
  -passphrase string
        Passphrase for encrypted YAML blob.
  -port string
        TCP port for server to run, default is ':8081' (default ":8081")
  -secretPath string
        Encrypted YAML blob containing string map of secrets.

encrypt: Perform encryption operations on a yaml file.
  -decrypt
        should the file be decrypted
  -filepath string
        File to perform encryption operation.
  -passphrase string
        Passphrase for encrypted YAML blob.

Example run

captainhook encrypt -filepath .\monzoSecrets.yaml -passphrase XXXXXXX
captainhook serve -configPath .\monzo2ynab.yml -passphrase XXXXXXX -secretPath .\monzoSecrets.yaml

Compiling

Go 1.13 is required to build the source code, simply run go install cmd/standalone/captainhook.go to install the binary to your gopath, then run the produced executable, located in $GOPATH/bin/

Docs

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssignFunction

func AssignFunction(rule *Rule)

TODO make this mapping more configurable./find out if there's a better way to do this. Maps the function to the rule type.

func DisplayFunc

func DisplayFunc(iw io.Writer, dataMap map[string]interface{}, rule *Rule) error

func Hook

func Hook(w http.ResponseWriter, r *http.Request, endpoint *Endpoint, secrets SecretEngine, log *log.Logger, dataBag *map[string]interface{})

Main routine that processes received hooks, obtaining endpoints and processing rules. Various error checking and validation happens at this stage, i.e mapping required secrets to dataBag. data bag is a map of input parameters passed to each rules function.

func NoOp

func NoOp(iw io.Writer, dataMap map[string]interface{}, rule *Rule) error

NoOp, do nothing.

func TemplateFunc

func TemplateFunc(iw io.Writer, dataMap map[string]interface{}, rule *Rule) error

Uses go templating to create a new json string from the input recieved.

Types

type Endpoint

type Endpoint struct {
	Name    string   `yaml:"name"`
	Secrets []string `yaml:"secrets"`
	Rules   []Rule   `yaml:"rules"`
}

Data structure contains information on an Endpoint, with associated rules and sources.

func (*Endpoint) GetRules

func (e *Endpoint) GetRules() ([]Rule, error)

Obtains the associated rules for an endpoint.

type EndpointService

type EndpointService interface {
	Endpoint(name string) (*Endpoint, error)
	Endpoints() ([]Endpoint, error)
	CreateEndpoint() error
	DeleteEndpoint() error
}

Interface provides an extensible way of implementing the EndpointService, this is used in various parts of the application logic to decouple implementations.

type Rule

type Rule struct {
	Type        string            `yaml:type`
	Destination string            `yaml:destination`
	Arguments   map[string]string `yaml:arguments`
	Secrets     []string          `yaml:secrets`
	Headers     map[string]string `yaml:headers`
	Echo        bool              `yaml:echo`
	// contains filtered or unexported fields
}

Contains rule state, is assigned a function based on type. Type mapped by AssignFunction.

func (*Rule) Execute

func (r *Rule) Execute(iw io.Writer, dataMap map[string]interface{}) error

Executes the function poitner associated to the rule.

func (Rule) GetArg

func (rule Rule) GetArg(name string) (string, error)

Checks the rule arguments map for value and returns it or error.

func (*Rule) SetFunction

func (r *Rule) SetFunction(f func(iw io.Writer, dataMap map[string]interface{}, r *Rule) error) error

Sets the function pointer of the rule.

type SecretEngine

type SecretEngine interface {
	GetTextSecret(name string) (string, error)
	ValidateEndpointConfig(endpoints []Endpoint) error
}

Directories

Path Synopsis
cmd
standalone command

Jump to

Keyboard shortcuts

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