1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-24 15:59:41 +02:00

feat(edge/templates): introduce edge app templates [EE-6209] (#10480)

This commit is contained in:
Chaim Lev-Ari 2023-11-14 14:54:44 +02:00 committed by GitHub
parent 95d96e1164
commit e1e90c9c1d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
58 changed files with 1142 additions and 365 deletions

View file

@ -1,19 +1,12 @@
package templates
import (
"io"
"net/http"
portainer "github.com/portainer/portainer/api"
httperror "github.com/portainer/portainer/pkg/libhttp/error"
"github.com/portainer/portainer/pkg/libhttp/response"
)
// introduced for swagger
type listResponse struct {
Version string
Templates []portainer.Template
}
// @id TemplateList
// @summary List available templates
// @description List available templates.
@ -26,22 +19,10 @@ type listResponse struct {
// @failure 500 "Server error"
// @router /templates [get]
func (handler *Handler) templateList(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
settings, err := handler.DataStore.Settings().Settings()
if err != nil {
return httperror.InternalServerError("Unable to retrieve settings from the database", err)
templates, httpErr := handler.fetchTemplates()
if httpErr != nil {
return httpErr
}
resp, err := http.Get(settings.TemplatesURL)
if err != nil {
return httperror.InternalServerError("Unable to retrieve templates via the network", err)
}
defer resp.Body.Close()
w.Header().Set("Content-Type", "application/json")
_, err = io.Copy(w, resp.Body)
if err != nil {
return httperror.InternalServerError("Unable to write templates from templates URL", err)
}
return nil
return response.JSON(w, templates)
}