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:
Jose Diaz-Gonzalez
2024-02-25 11:10:36 -05:00
parent 412c841860
commit ba3ad4a9ab
5 changed files with 93 additions and 9 deletions

View File

@@ -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
}