fix: do not allow reusing the same scheme:host-port mappings when setting ports
This doesn't make sense as a port can't be listened to twice on the same domain, so instead we should just fail immediately if someone attempts to perform this action. Refs dokku/dokku-letsencrypt#269
This commit is contained in:
@@ -2,6 +2,7 @@ package ports
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
@@ -31,6 +32,16 @@ func CommandAdd(appName string, portMapStrings []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := reusesSchemeHostPort(portMaps); err != nil {
|
||||
return fmt.Errorf("Error validating new port mappings: %s", err)
|
||||
}
|
||||
|
||||
existingPortMaps := getPortMaps(appName)
|
||||
allPortMaps := append(existingPortMaps, portMaps...)
|
||||
if err := reusesSchemeHostPort(allPortMaps); err != nil {
|
||||
return fmt.Errorf("Error validating all port mappings: %s", err)
|
||||
}
|
||||
|
||||
if err := addPortMaps(appName, portMaps); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -88,6 +99,10 @@ func CommandSet(appName string, portMapStrings []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := reusesSchemeHostPort(portMaps); err != nil {
|
||||
return fmt.Errorf("Error validating port mappings: %s", err)
|
||||
}
|
||||
|
||||
if err := setPortMaps(appName, portMaps); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user