mirror of https://github.com/portainer/portainer
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 ComposeStackManagerpull/5347/head
parent
fe07815fc7
commit
09c5bada3e
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
wrapper "github.com/portainer/docker-compose-wrapper"
|
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
|
// NormalizeStackName returns a new stack name with unsupported characters replaced
|
||||||
func (w *ComposeStackManager) NormalizeStackName(name string) string {
|
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
|
// ComposeSyntaxMaxVersion returns the maximum supported version of the docker compose syntax
|
||||||
|
|
|
@ -8,7 +8,9 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
|
"regexp"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strings"
|
||||||
|
|
||||||
portainer "github.com/portainer/portainer/api"
|
portainer "github.com/portainer/portainer/api"
|
||||||
)
|
)
|
||||||
|
@ -184,3 +186,8 @@ func (manager *SwarmStackManager) retrieveConfigurationFromDisk(path string) (ma
|
||||||
|
|
||||||
return config, nil
|
return config, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (manager *SwarmStackManager) NormalizeStackName(name string) string {
|
||||||
|
r := regexp.MustCompile("[^a-z0-9]+")
|
||||||
|
return r.ReplaceAllString(strings.ToLower(name), "")
|
||||||
|
}
|
||||||
|
|
|
@ -47,6 +47,8 @@ func (handler *Handler) createSwarmStackFromFileContent(w http.ResponseWriter, r
|
||||||
return &httperror.HandlerError{http.StatusBadRequest, "Invalid request payload", err}
|
return &httperror.HandlerError{http.StatusBadRequest, "Invalid request payload", err}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
payload.Name = handler.SwarmStackManager.NormalizeStackName(payload.Name)
|
||||||
|
|
||||||
isUnique, err := handler.checkUniqueName(endpoint, payload.Name, 0, true)
|
isUnique, err := handler.checkUniqueName(endpoint, payload.Name, 0, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to check for name collision", err}
|
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to check for name collision", err}
|
||||||
|
@ -148,6 +150,8 @@ func (handler *Handler) createSwarmStackFromGitRepository(w http.ResponseWriter,
|
||||||
return &httperror.HandlerError{http.StatusBadRequest, "Invalid request payload", err}
|
return &httperror.HandlerError{http.StatusBadRequest, "Invalid request payload", err}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
payload.Name = handler.SwarmStackManager.NormalizeStackName(payload.Name)
|
||||||
|
|
||||||
isUnique, err := handler.checkUniqueName(endpoint, payload.Name, 0, true)
|
isUnique, err := handler.checkUniqueName(endpoint, payload.Name, 0, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to check for name collision", err}
|
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to check for name collision", err}
|
||||||
|
@ -244,6 +248,8 @@ func (handler *Handler) createSwarmStackFromFileUpload(w http.ResponseWriter, r
|
||||||
return &httperror.HandlerError{http.StatusBadRequest, "Invalid request payload", err}
|
return &httperror.HandlerError{http.StatusBadRequest, "Invalid request payload", err}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
payload.Name = handler.SwarmStackManager.NormalizeStackName(payload.Name)
|
||||||
|
|
||||||
isUnique, err := handler.checkUniqueName(endpoint, payload.Name, 0, true)
|
isUnique, err := handler.checkUniqueName(endpoint, payload.Name, 0, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to check for name collision", err}
|
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to check for name collision", err}
|
||||||
|
|
|
@ -1280,6 +1280,7 @@ type (
|
||||||
Logout(endpoint *Endpoint) error
|
Logout(endpoint *Endpoint) error
|
||||||
Deploy(stack *Stack, prune bool, endpoint *Endpoint) error
|
Deploy(stack *Stack, prune bool, endpoint *Endpoint) error
|
||||||
Remove(stack *Stack, endpoint *Endpoint) error
|
Remove(stack *Stack, endpoint *Endpoint) error
|
||||||
|
NormalizeStackName(name string) string
|
||||||
}
|
}
|
||||||
|
|
||||||
// TagService represents a service for managing tag data
|
// TagService represents a service for managing tag data
|
||||||
|
|
Loading…
Reference in New Issue