fix(api): use EntryPoint as a reference to overwrite stack Compose file (#1725)

pull/1722/head^2
Anthony Lapenna 2018-03-13 21:35:12 +10:00 committed by GitHub
parent d34b1d5f9d
commit 706490db5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 9 deletions

View File

@ -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. // 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. // 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) stackStorePath := path.Join(ComposeStorePath, stackIdentifier)
err := service.createDirectoryInStoreIfNotExist(stackStorePath) err := service.createDirectoryInStoreIfNotExist(stackStorePath)
if err != nil { if err != nil {
return "", err return "", err
} }
composeFilePath := path.Join(stackStorePath, ComposeFileDefaultName) composeFilePath := path.Join(stackStorePath, fileName)
data := []byte(stackFileContent) data := []byte(stackFileContent)
r := bytes.NewReader(data) 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. // 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. // 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) stackStorePath := path.Join(ComposeStorePath, stackIdentifier)
err := service.createDirectoryInStoreIfNotExist(stackStorePath) err := service.createDirectoryInStoreIfNotExist(stackStorePath)
if err != nil { if err != nil {
return "", err return "", err
} }
composeFilePath := path.Join(stackStorePath, ComposeFileDefaultName) composeFilePath := path.Join(stackStorePath, fileName)
err = service.createFileInStore(composeFilePath, r) err = service.createFileInStore(composeFilePath, r)
if err != nil { if err != nil {

View File

@ -179,7 +179,7 @@ func (handler *StackHandler) handlePostStacksStringMethod(w http.ResponseWriter,
Env: req.Env, 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 { if err != nil {
httperror.WriteErrorResponse(w, err, http.StatusInternalServerError, handler.Logger) httperror.WriteErrorResponse(w, err, http.StatusInternalServerError, handler.Logger)
return return
@ -431,7 +431,7 @@ func (handler *StackHandler) handlePostStacksFileMethod(w http.ResponseWriter, r
Env: env, 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 { if err != nil {
httperror.WriteErrorResponse(w, err, http.StatusInternalServerError, handler.Logger) httperror.WriteErrorResponse(w, err, http.StatusInternalServerError, handler.Logger)
return return
@ -631,7 +631,7 @@ func (handler *StackHandler) handlePutStack(w http.ResponseWriter, r *http.Reque
} }
stack.Env = req.Env 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 { if err != nil {
httperror.WriteErrorResponse(w, err, http.StatusInternalServerError, handler.Logger) httperror.WriteErrorResponse(w, err, http.StatusInternalServerError, handler.Logger)
return return

View File

@ -369,8 +369,8 @@ type (
DeleteTLSFile(folder string, fileType TLSFileType) error DeleteTLSFile(folder string, fileType TLSFileType) error
DeleteTLSFiles(folder string) error DeleteTLSFiles(folder string) error
GetStackProjectPath(stackIdentifier string) string GetStackProjectPath(stackIdentifier string) string
StoreStackFileFromString(stackIdentifier string, stackFileContent string) (string, error) StoreStackFileFromString(stackIdentifier, fileName, stackFileContent string) (string, error)
StoreStackFileFromReader(stackIdentifier string, r io.Reader) (string, error) StoreStackFileFromReader(stackIdentifier, fileName string, r io.Reader) (string, error)
} }
// GitService represents a service for managing Git. // GitService represents a service for managing Git.