hook

package
v0.0.0-...-f9ef937 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2020 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AppName is the name of the app.
	AppName = "hook"
)

Variables

View Source
var (
	// DefaultCatalog is the default catalog installed automatically for users.
	DefaultCatalog = &RemoteConfig{
		Name: "@",
		URL:  "https://github.com/eddiezane/hook-catalog",
	}
)
View Source
var (
	// Transformers are the default set of transformers.
	Transformers = map[TransformStrategy]Transformer{
		TransformBase64: Base64Transformer{},
	}
)

Functions

func Initcfg

func Initcfg()

Initcfg intializes the config environment. This is not done as a part of the standard Go init function so that we can override environment specific variables (such as $HOME) in tests.

func ParsePath

func ParsePath(uri string) (catalog string, path string)

ParsePath takes a hook name of the form <catalog>@<path> and returns the individual pieces.

func ShowHook

func ShowHook(w io.Writer, uri ...string) error

ShowHook writes the given hooks specified by the URI to a Writer.

Types

type Base64Transformer

type Base64Transformer struct{}

Base64Transformer handles base64 transformations.

func (Base64Transformer) Decode

func (Base64Transformer) Decode(raw string, path string) (string, error)

Decode takes the given payload + path and base64 decodes the value.

func (Base64Transformer) Encode

func (Base64Transformer) Encode(json string, path string) (string, error)

Encode takes the given payload + path and base64 encodes the value.

func (Base64Transformer) Type

Type returns the strategy type of the transformer.

type Catalog

type Catalog interface {
	Open(path string) (*os.File, error)
}

Catalog represents a mechanism for fetching hook configurations.

type CatalogConfig

type CatalogConfig struct {
	Remote []*RemoteConfig
}

CatalogConfig describes the hook remote catalog.

func (CatalogConfig) Sort

func (c CatalogConfig) Sort()

Sort deterministically sorts the Catalog, useful for consistent ordering for tests.

type Config

type Config struct {
	Cache   string
	Catalog *CatalogConfig
}

Config descirbes configuration for hook settings.

type Hook

type Hook struct {
	Method  string      `yaml:"method"`
	Headers http.Header `yaml:"headers,omitempty"`
	Body    string      `yaml:"body,omitempty"`
	Params  url.Values  `yaml:"params,omitempty"`

	Transform map[TransformStrategy][]string `yaml:",omitempty"`
}

Hook represents a single hook configuration.

func New

func New(r io.Reader) ([]*Hook, error)

New creates a new Hook from the given bytestring.

func NewFromPath

func NewFromPath(path string) ([]*Hook, error)

NewFromPath creates a new Hook from the given path.

func NewFromRequest

func NewFromRequest(r *http.Request, opts ...Option) (*Hook, error)

NewFromRequest creates a new Hook from the given HTTP Request.

func (*Hook) Dump

func (h *Hook) Dump() ([]byte, error)

Dump TODO(eddiezane): Is this the right method?

func (*Hook) Fire

func (h *Hook) Fire(target string) (*http.Response, error)

Fire sends an HTTP request to the given target.

type LocalCatalog

type LocalCatalog struct{}

LocalCatalog handles reading configuration locally.

func (LocalCatalog) Open

func (LocalCatalog) Open(path string) (*os.File, error)

Open returns the local file. This is a wrapper around os.Open.

type Option

type Option interface {
	Apply(h *Hook) error
}

Option allows for optional modifications to be made onto the new hook.

func DecodeOption

func DecodeOption(t Transformer, paths ...string) Option

DecodeOption modifies newly hooks by applying the transformer.Decode for the specified paths.

type RemoteConfig

type RemoteConfig struct {
	Name     string
	URL      string
	Revision string `yaml:",omitempty"`
}

RemoteConfig describes a single catalog remote.

func GetRemoteConfig

func GetRemoteConfig(catalog string) (*RemoteConfig, error)

GetRemoteConfig resolves a catalog name into the underlying remote config. If the catalog doesn't exist, an error is returned.

func (*RemoteConfig) Clone

func (rc *RemoteConfig) Clone() error

Clone clones the remote catalog to the hook cache.

func (*RemoteConfig) Open

func (rc *RemoteConfig) Open(path string) (*os.File, error)

Open returns the file corresponding to the file in the remote config, cloning the config locally if it has not occured yet.

func (RemoteConfig) Path

func (rc RemoteConfig) Path() string

Path returns the cache path where the remote cache exists.

func (*RemoteConfig) Update

func (rc *RemoteConfig) Update() error

Update pulls the latest version of the catalog to the hook cache. If the catalog does not exist in the cache, it is cloned.

type RemoteConfigSet

type RemoteConfigSet map[string]*RemoteConfig

RemoteConfigSet maps remote config names to the complete remote config.

func GetRemoteConfigs

func GetRemoteConfigs() (RemoteConfigSet, error)

GetRemoteConfigs gets the current remote catalog configuration. Returns a map so that values can easily be treated as a set.

func (RemoteConfigSet) Get

func (r RemoteConfigSet) Get(name string) (*RemoteConfig, error)

Get returns the RemoteConfig if it exists, or an error if it was missing.

type TransformStrategy

type TransformStrategy string

TransformStrategy denotes an operation to take on a field.

const (
	// TransformBase64 denotes that the field should be base64 encoded/decoded.
	TransformBase64 TransformStrategy = "base64"
)

type Transformer

type Transformer interface {
	Encode(json string, path string) (string, error)
	Decode(json string, path string) (string, error)
	Type() TransformStrategy
}

Transformer defines the encoding and decoding methods for message transformation.

Jump to

Keyboard shortcuts

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