fix(custom-templates): avoid creation of template if the compose file does not exist EE-1470 (#6011)

fix(custom-templates): avoid creation of template if the compose file does not exist EE-1470
pull/6083/head
andres-portainer 2021-11-12 11:02:10 -03:00 committed by GitHub
parent cc3b1face2
commit a2886115b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package customtemplates
import (
"errors"
"log"
"net/http"
"regexp"
"strconv"
@ -270,6 +271,23 @@ func (handler *Handler) createCustomTemplateFromGitRepository(r *http.Request) (
return nil, err
}
entryPath := filesystem.JoinPaths(projectPath, customTemplate.EntryPoint)
exists, err := handler.FileService.FileExists(entryPath)
if err != nil || !exists {
if err := handler.FileService.RemoveDirectory(projectPath); err != nil {
log.Printf("[WARN] [http,customtemplate,git] [error: %s] [message: unable to remove git repository directory]", err)
}
}
if err != nil {
return nil, err
}
if !exists {
return nil, errors.New("Invalid Compose file, ensure that the Compose file path is correct")
}
return customTemplate, nil
}