mirror of
https://github.com/portainer/portainer.git
synced 2025-07-22 23:09:41 +02:00
fix(libclient): option to disable external http request [BE-11696] (#745)
This commit is contained in:
parent
ee65223ee7
commit
e243a6bf1c
5 changed files with 51 additions and 2 deletions
|
@ -4,7 +4,9 @@ import (
|
|||
"net/http"
|
||||
|
||||
portainer "github.com/portainer/portainer/api"
|
||||
libclient "github.com/portainer/portainer/pkg/libhttp/client"
|
||||
httperror "github.com/portainer/portainer/pkg/libhttp/error"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/segmentio/encoding/json"
|
||||
)
|
||||
|
||||
|
@ -24,13 +26,20 @@ func (handler *Handler) fetchTemplates() (*listResponse, *httperror.HandlerError
|
|||
templatesURL = portainer.DefaultTemplatesURL
|
||||
}
|
||||
|
||||
var body *listResponse
|
||||
if err := libclient.ExternalRequestDisabled(templatesURL); err != nil {
|
||||
if templatesURL == portainer.DefaultTemplatesURL {
|
||||
log.Debug().Err(err).Msg("External request disabled: Default templates")
|
||||
return body, nil
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue