mirror of
https://github.com/dokku/dokku.git
synced 2026-08-29 10:08:53 +02:00
The alias was only ever used to build the `include_labels` filter on the generated vector source, while dokku labels containers with `com.dokku.app-name` unconditionally. Setting the property therefore pointed the source at a label no container carries, and log collection stopped without any error. The source now always filters the label dokku applies, and a generated remap renames the field on its way to the sink, which is what the property was documented to do. An app whose own alias differs from the global one gets a branch in the global pipeline, so a per-app value is honored even when the app ships through the global sink. Closes #8916.
130 lines
2.9 KiB
Go
130 lines
2.9 KiB
Go
package logs
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"regexp"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/dokku/dokku/plugins/common"
|
|
)
|
|
|
|
func validateSetValue(appName string, key string, value string) error {
|
|
if key == "app-label-alias" {
|
|
return validateAppLabelAlias(appName, value)
|
|
}
|
|
|
|
if key == "max-size" {
|
|
return validateMaxSize(appName, value)
|
|
}
|
|
|
|
if key == "vector-image" {
|
|
return validateVectorImage(appName, value)
|
|
}
|
|
|
|
if key == "vector-networks" {
|
|
return validateVectorNetworks(appName, value)
|
|
}
|
|
|
|
if key == "vector-sink" || key == "vector-cron-sink" {
|
|
return validateVectorSink(appName, value)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// appLabelAliasPattern matches label keys that are safe to both use as a docker
|
|
// label and quote into the generated vector remap program
|
|
var appLabelAliasPattern = regexp.MustCompile(`^[A-Za-z0-9][A-Za-z0-9_.-]*$`)
|
|
|
|
func validateAppLabelAlias(appName string, value string) error {
|
|
if value == "" {
|
|
return nil
|
|
}
|
|
|
|
if !appLabelAliasPattern.MatchString(value) {
|
|
return errors.New("Invalid app-label-alias value, must start with a letter or number and contain only letters, numbers, and any of [_, ., -]")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func validateMaxSize(appName string, value string) error {
|
|
if value == "" {
|
|
return nil
|
|
}
|
|
|
|
if value == "unlimited" {
|
|
return nil
|
|
}
|
|
|
|
last := value[len(value)-1:]
|
|
if last != "k" && last != "m" && last != "g" {
|
|
return errors.New("Invalid max-size unit measure, value must end in any of [k, m, g]")
|
|
}
|
|
|
|
if len(value) < 2 {
|
|
return errors.New("Invalid max-size value, must be a number followed by a unit of measure [k, m, g]")
|
|
}
|
|
|
|
number := value[:len(value)-1]
|
|
if _, err := strconv.Atoi(number); err != nil {
|
|
return fmt.Errorf("Invalid max-size value, unable to convert number to int: %s", err.Error())
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func validateVectorSink(appName string, value string) error {
|
|
if value == "" {
|
|
return nil
|
|
}
|
|
|
|
_, err := SinkValueToConfig(SinkValueToConfigInput{SinkValue: value})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func validateVectorImage(appName string, value string) error {
|
|
if appName != "--global" {
|
|
return errors.New("vector-image may only be set globally with --global")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func validateVectorNetworks(appName string, value string) error {
|
|
if appName != "--global" {
|
|
return errors.New("vector-networks may only be set globally with --global")
|
|
}
|
|
|
|
if value == "" {
|
|
return nil
|
|
}
|
|
|
|
for _, name := range strings.Split(value, ",") {
|
|
name = strings.TrimSpace(name)
|
|
if name == "" {
|
|
return errors.New("Invalid vector-networks value, empty entry in comma-separated list")
|
|
}
|
|
|
|
if name == "bridge" {
|
|
return errors.New("Invalid vector-networks value, \"bridge\" is not a valid entry for vector-networks")
|
|
}
|
|
|
|
result, err := common.CallExecCommand(common.ExecCommandInput{
|
|
Command: common.DockerBin(),
|
|
Args: []string{"network", "inspect", name},
|
|
})
|
|
if err != nil || result.ExitCode != 0 {
|
|
return fmt.Errorf("Network %q does not exist", name)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|