mirror of
https://github.com/portainer/portainer.git
synced 2025-07-24 07:49:41 +02:00
feat(edge/templates): introduce edge app templates [EE-6209] (#10480)
This commit is contained in:
parent
95d96e1164
commit
e1e90c9c1d
58 changed files with 1142 additions and 365 deletions
41
api/http/handler/templates/utils_fetch_templates.go
Normal file
41
api/http/handler/templates/utils_fetch_templates.go
Normal file
|
@ -0,0 +1,41 @@
|
|||
package templates
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
portainer "github.com/portainer/portainer/api"
|
||||
httperror "github.com/portainer/portainer/pkg/libhttp/error"
|
||||
"github.com/segmentio/encoding/json"
|
||||
)
|
||||
|
||||
type listResponse struct {
|
||||
Version string `json:"version"`
|
||||
Templates []portainer.Template `json:"templates"`
|
||||
}
|
||||
|
||||
func (handler *Handler) fetchTemplates() (*listResponse, *httperror.HandlerError) {
|
||||
settings, err := handler.DataStore.Settings().Settings()
|
||||
if err != nil {
|
||||
return nil, httperror.InternalServerError("Unable to retrieve settings from the database", err)
|
||||
}
|
||||
|
||||
templatesURL := settings.TemplatesURL
|
||||
if templatesURL == "" {
|
||||
templatesURL = portainer.DefaultTemplatesURL
|
||||
}
|
||||
|
||||
resp, err := http.Get(templatesURL)
|
||||
if err != nil {
|
||||
return nil, httperror.InternalServerError("Unable to retrieve templates via the network", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
var body *listResponse
|
||||
err = json.NewDecoder(resp.Body).Decode(&body)
|
||||
if err != nil {
|
||||
return nil, httperror.InternalServerError("Unable to parse template file", err)
|
||||
}
|
||||
|
||||
return body, nil
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue