2018-12-09 03:49:27 +00:00
|
|
|
package extensions
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
httperror "github.com/portainer/libhttp/error"
|
|
|
|
"github.com/portainer/libhttp/request"
|
|
|
|
"github.com/portainer/libhttp/response"
|
2019-03-21 01:20:14 +00:00
|
|
|
"github.com/portainer/portainer/api"
|
2020-07-07 21:57:52 +00:00
|
|
|
"github.com/portainer/portainer/api/bolt/errors"
|
|
|
|
"github.com/portainer/portainer/api/http/client"
|
2018-12-09 03:49:27 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// GET request on /api/extensions/:id
|
|
|
|
func (handler *Handler) extensionInspect(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
|
|
|
|
extensionIdentifier, err := request.RetrieveNumericRouteVariableValue(r, "id")
|
|
|
|
if err != nil {
|
|
|
|
return &httperror.HandlerError{http.StatusBadRequest, "Invalid extension identifier route variable", err}
|
|
|
|
}
|
2019-11-20 05:16:40 +00:00
|
|
|
|
2018-12-09 03:49:27 +00:00
|
|
|
extensionID := portainer.ExtensionID(extensionIdentifier)
|
|
|
|
|
2019-11-20 05:16:40 +00:00
|
|
|
definitions, err := handler.ExtensionManager.FetchExtensionDefinitions()
|
2018-12-09 03:49:27 +00:00
|
|
|
if err != nil {
|
2019-11-20 05:16:40 +00:00
|
|
|
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve extensions informations", err}
|
2018-12-09 03:49:27 +00:00
|
|
|
}
|
|
|
|
|
2020-05-20 05:23:15 +00:00
|
|
|
localExtension, err := handler.DataStore.Extension().Extension(extensionID)
|
2020-07-07 21:57:52 +00:00
|
|
|
if err != nil && err != errors.ErrObjectNotFound {
|
2019-11-20 05:16:40 +00:00
|
|
|
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve extension information from the database", err}
|
2018-12-09 03:49:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var extension portainer.Extension
|
2019-11-20 05:16:40 +00:00
|
|
|
var extensionDefinition portainer.Extension
|
|
|
|
|
|
|
|
for _, definition := range definitions {
|
|
|
|
if definition.ID == extensionID {
|
|
|
|
extensionDefinition = definition
|
2018-12-09 03:49:27 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-20 05:16:40 +00:00
|
|
|
if localExtension == nil {
|
|
|
|
extension = extensionDefinition
|
|
|
|
} else {
|
|
|
|
extension = *localExtension
|
2018-12-09 03:49:27 +00:00
|
|
|
}
|
|
|
|
|
2019-11-20 05:16:40 +00:00
|
|
|
mergeExtensionAndDefinition(&extension, &extensionDefinition)
|
2018-12-09 03:49:27 +00:00
|
|
|
|
2019-11-20 05:16:40 +00:00
|
|
|
description, _ := client.Get(extension.DescriptionURL, 5)
|
|
|
|
extension.Description = string(description)
|
2018-12-09 03:49:27 +00:00
|
|
|
|
|
|
|
return response.JSON(w, extension)
|
|
|
|
}
|