Documentation ¶
Index ¶
- Constants
- Variables
- func Initcfg()
- func ParsePath(uri string) (catalog string, path string)
- func ShowHook(w io.Writer, uri ...string) error
- type Base64Transformer
- type Catalog
- type CatalogConfig
- type Config
- type Hook
- type LocalCatalog
- type Option
- type RemoteConfig
- type RemoteConfigSet
- type TransformStrategy
- type Transformer
Constants ¶
const (
// AppName is the name of the app.
AppName = "hook"
)
Variables ¶
var ( // DefaultCatalog is the default catalog installed automatically for users. DefaultCatalog = &RemoteConfig{ Name: "@", URL: "https://github.com/eddiezane/hook-catalog", } )
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.
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 ¶
func (Base64Transformer) Type() TransformStrategy
Type returns the strategy type of the transformer.
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 NewFromPath ¶
NewFromPath creates a new Hook from the given path.
func NewFromRequest ¶
NewFromRequest creates a new Hook from the given HTTP Request.
type Option ¶
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 ¶
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" )