fix(app): fix create stack with capital letters or space issue EE-908 (#5236)

* fix(app): fix create stack with capital letters or space issue

* replace ComposeWrapper with ComposeStackManager
This commit is contained in:
Richard Wei
2021-07-23 09:53:42 +12:00
committed by GitHub
parent fe07815fc7
commit 09c5bada3e
4 changed files with 17 additions and 1 deletions

View File

@@ -4,6 +4,7 @@ import (
"fmt"
"os"
"path"
"regexp"
"strings"
wrapper "github.com/portainer/docker-compose-wrapper"
@@ -36,7 +37,8 @@ func NewComposeStackManager(binaryPath string, configPath string, proxyManager *
// NormalizeStackName returns a new stack name with unsupported characters replaced
func (w *ComposeStackManager) NormalizeStackName(name string) string {
return name
r := regexp.MustCompile("[^a-z0-9]+")
return r.ReplaceAllString(strings.ToLower(name), "")
}
// ComposeSyntaxMaxVersion returns the maximum supported version of the docker compose syntax

View File

@@ -8,7 +8,9 @@ import (
"os"
"os/exec"
"path"
"regexp"
"runtime"
"strings"
portainer "github.com/portainer/portainer/api"
)
@@ -184,3 +186,8 @@ func (manager *SwarmStackManager) retrieveConfigurationFromDisk(path string) (ma
return config, nil
}
func (manager *SwarmStackManager) NormalizeStackName(name string) string {
r := regexp.MustCompile("[^a-z0-9]+")
return r.ReplaceAllString(strings.ToLower(name), "")
}