mirror of
https://github.com/adnanh/webhook.git
synced 2025-05-22 21:32:32 +00:00
Add support for naming env variables (#75)
* Adding ignore patterns * Adding support for env var naming * Fixed typo in docstring * Adding tests for the env var extraction w & w/o explicit naming * remove coverage script from ignore patterns * Adding the coverage script to help see which code is tested and which is not * remove coverage script from sources * Ignore coverage script from sources tree
This commit is contained in:
parent
e85e0592dd
commit
18b0573bc4
3 changed files with 113 additions and 41 deletions
13
hook/hook.go
13
hook/hook.go
|
@ -196,8 +196,9 @@ func ExtractParameterAsString(s string, params interface{}) (string, bool) {
|
|||
// Argument type specifies the parameter key name and the source it should
|
||||
// be extracted from
|
||||
type Argument struct {
|
||||
Source string `json:"source,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Source string `json:"source,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
EnvName string `json:"envname,omitempty"`
|
||||
}
|
||||
|
||||
// Get Argument method returns the value for the Argument's key name
|
||||
|
@ -364,7 +365,13 @@ func (h *Hook) ExtractCommandArgumentsForEnv(headers, query, payload *map[string
|
|||
|
||||
for i := range h.PassEnvironmentToCommand {
|
||||
if arg, ok := h.PassEnvironmentToCommand[i].Get(headers, query, payload); ok {
|
||||
args = append(args, EnvNamespace+h.PassEnvironmentToCommand[i].Name+"="+arg)
|
||||
if h.PassEnvironmentToCommand[i].EnvName != "" {
|
||||
// first try to use the EnvName if specified
|
||||
args = append(args, EnvNamespace+h.PassEnvironmentToCommand[i].EnvName+"="+arg)
|
||||
} else {
|
||||
// then fallback on the name
|
||||
args = append(args, EnvNamespace+h.PassEnvironmentToCommand[i].Name+"="+arg)
|
||||
}
|
||||
} else {
|
||||
return args, &ArgumentError{h.PassEnvironmentToCommand[i]}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue