refactor: force-set the type and inputs for a vector sink

Previously, a user could inadvertently override the type or the inputs value by specifying those in their config. Instead, we force-set these so that users do not have potentially invalid config.
This commit is contained in:
Jose Diaz-Gonzalez
2021-09-10 23:03:29 -04:00
parent 2a04ed70b6
commit 2c4fec77bb

View File

@@ -128,23 +128,9 @@ func sinkValueToConfig(appName string, sinkValue string) (vectorSink, error) {
u.Scheme = strings.ReplaceAll(u.Scheme, "-", "_")
t := fmt.Sprintf("type=%s", u.Scheme)
i := fmt.Sprintf("inputs[]=docker-source:%s", appName)
if appName == "--global" {
i = "inputs[]=docker-global-source"
}
if appName == "--null" {
i = "inputs[]=docker-null-source"
}
initialQuery := fmt.Sprintf("%s&%s", t, i)
query := u.RawQuery
if query == "" {
query = initialQuery
} else if strings.HasPrefix(query, "&") {
query = fmt.Sprintf("%s%s", initialQuery, query)
} else {
query = fmt.Sprintf("%s&%s", initialQuery, query)
if strings.HasPrefix(query, "&") {
query = strings.TrimPrefix(query, "&")
}
b, err := qson.ToJSON(query)
@@ -156,6 +142,15 @@ func sinkValueToConfig(appName string, sinkValue string) (vectorSink, error) {
return data, err
}
data["type"] = u.Scheme
data["inputs"] = []string{"docker-source:" + appName}
if appName == "--global" {
data["inputs"] = []string{"docker-global-source"}
}
if appName == "--null" {
data["inputs"] = []string{"docker-null-source"}
}
return data, nil
}