From 706490db5e37b6303489dba838c9fce56fc668cc Mon Sep 17 00:00:00 2001 From: Anthony Lapenna Date: Tue, 13 Mar 2018 21:35:12 +1000 Subject: [PATCH] fix(api): use EntryPoint as a reference to overwrite stack Compose file (#1725) --- api/filesystem/filesystem.go | 8 ++++---- api/http/handler/stack.go | 6 +++--- api/portainer.go | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/api/filesystem/filesystem.go b/api/filesystem/filesystem.go index 236845410..26eff582d 100644 --- a/api/filesystem/filesystem.go +++ b/api/filesystem/filesystem.go @@ -76,14 +76,14 @@ func (service *Service) GetStackProjectPath(stackIdentifier string) string { // StoreStackFileFromString creates a subfolder in the ComposeStorePath and stores a new file using the content from a string. // It returns the path to the folder where the file is stored. -func (service *Service) StoreStackFileFromString(stackIdentifier, stackFileContent string) (string, error) { +func (service *Service) StoreStackFileFromString(stackIdentifier, fileName, stackFileContent string) (string, error) { stackStorePath := path.Join(ComposeStorePath, stackIdentifier) err := service.createDirectoryInStoreIfNotExist(stackStorePath) if err != nil { return "", err } - composeFilePath := path.Join(stackStorePath, ComposeFileDefaultName) + composeFilePath := path.Join(stackStorePath, fileName) data := []byte(stackFileContent) r := bytes.NewReader(data) @@ -97,14 +97,14 @@ func (service *Service) StoreStackFileFromString(stackIdentifier, stackFileConte // StoreStackFileFromReader creates a subfolder in the ComposeStorePath and stores a new file using the content from an io.Reader. // It returns the path to the folder where the file is stored. -func (service *Service) StoreStackFileFromReader(stackIdentifier string, r io.Reader) (string, error) { +func (service *Service) StoreStackFileFromReader(stackIdentifier, fileName string, r io.Reader) (string, error) { stackStorePath := path.Join(ComposeStorePath, stackIdentifier) err := service.createDirectoryInStoreIfNotExist(stackStorePath) if err != nil { return "", err } - composeFilePath := path.Join(stackStorePath, ComposeFileDefaultName) + composeFilePath := path.Join(stackStorePath, fileName) err = service.createFileInStore(composeFilePath, r) if err != nil { diff --git a/api/http/handler/stack.go b/api/http/handler/stack.go index 86b597e40..ff872896d 100644 --- a/api/http/handler/stack.go +++ b/api/http/handler/stack.go @@ -179,7 +179,7 @@ func (handler *StackHandler) handlePostStacksStringMethod(w http.ResponseWriter, Env: req.Env, } - projectPath, err := handler.FileService.StoreStackFileFromString(string(stack.ID), stackFileContent) + projectPath, err := handler.FileService.StoreStackFileFromString(string(stack.ID), stack.EntryPoint, stackFileContent) if err != nil { httperror.WriteErrorResponse(w, err, http.StatusInternalServerError, handler.Logger) return @@ -431,7 +431,7 @@ func (handler *StackHandler) handlePostStacksFileMethod(w http.ResponseWriter, r Env: env, } - projectPath, err := handler.FileService.StoreStackFileFromReader(string(stack.ID), stackFile) + projectPath, err := handler.FileService.StoreStackFileFromReader(string(stack.ID), stack.EntryPoint, stackFile) if err != nil { httperror.WriteErrorResponse(w, err, http.StatusInternalServerError, handler.Logger) return @@ -631,7 +631,7 @@ func (handler *StackHandler) handlePutStack(w http.ResponseWriter, r *http.Reque } stack.Env = req.Env - _, err = handler.FileService.StoreStackFileFromString(string(stack.ID), req.StackFileContent) + _, err = handler.FileService.StoreStackFileFromString(string(stack.ID), stack.EntryPoint, req.StackFileContent) if err != nil { httperror.WriteErrorResponse(w, err, http.StatusInternalServerError, handler.Logger) return diff --git a/api/portainer.go b/api/portainer.go index f001f83df..8c60b9973 100644 --- a/api/portainer.go +++ b/api/portainer.go @@ -369,8 +369,8 @@ type ( DeleteTLSFile(folder string, fileType TLSFileType) error DeleteTLSFiles(folder string) error GetStackProjectPath(stackIdentifier string) string - StoreStackFileFromString(stackIdentifier string, stackFileContent string) (string, error) - StoreStackFileFromReader(stackIdentifier string, r io.Reader) (string, error) + StoreStackFileFromString(stackIdentifier, fileName, stackFileContent string) (string, error) + StoreStackFileFromReader(stackIdentifier, fileName string, r io.Reader) (string, error) } // GitService represents a service for managing Git.