EventManager: support placeholders within URL paths

Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
Nicola Murino
2023-01-22 08:46:58 +01:00
parent 707729ee61
commit 3ce4d04b27
5 changed files with 52 additions and 10 deletions

View File

@@ -1029,11 +1029,22 @@ func checkEventGroupConditionPatters(groups []sdk.GroupMapping, patterns []datap
}
func getHTTPRuleActionEndpoint(c dataprovider.EventActionHTTPConfig, replacer *strings.Replacer) (string, error) {
if len(c.QueryParameters) > 0 {
u, err := url.Parse(c.Endpoint)
if err != nil {
return "", fmt.Errorf("invalid endpoint: %w", err)
u, err := url.Parse(c.Endpoint)
if err != nil {
return "", fmt.Errorf("invalid endpoint: %w", err)
}
if strings.Contains(u.Path, "{{") {
pathComponents := strings.Split(u.Path, "/")
for idx := range pathComponents {
part := replaceWithReplacer(pathComponents[idx], replacer)
if part != pathComponents[idx] {
pathComponents[idx] = url.PathEscape(part)
}
}
u.Path = ""
u = u.JoinPath(pathComponents...)
}
if len(c.QueryParameters) > 0 {
q := u.Query()
for _, keyVal := range c.QueryParameters {
@@ -1041,9 +1052,8 @@ func getHTTPRuleActionEndpoint(c dataprovider.EventActionHTTPConfig, replacer *s
}
u.RawQuery = q.Encode()
return u.String(), nil
}
return c.Endpoint, nil
return u.String(), nil
}
func writeHTTPPart(m *multipart.Writer, part dataprovider.HTTPPart, h textproto.MIMEHeader,