2018-12-09 03:49:27 +00:00
|
|
|
package extensions
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/coreos/go-semver/semver"
|
|
|
|
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"
|
2018-12-09 03:49:27 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// GET request on /api/extensions?store=<store>
|
|
|
|
func (handler *Handler) extensionList(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
|
|
|
|
storeDetails, _ := request.RetrieveBooleanQueryParameter(r, "store", true)
|
|
|
|
|
|
|
|
extensions, err := handler.ExtensionService.Extensions()
|
|
|
|
if err != nil {
|
|
|
|
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve extensions from the database", err}
|
|
|
|
}
|
|
|
|
|
|
|
|
if storeDetails {
|
|
|
|
definitions, err := handler.ExtensionManager.FetchExtensionDefinitions()
|
|
|
|
if err != nil {
|
2018-12-11 21:28:21 +00:00
|
|
|
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve extensions", err}
|
2018-12-09 03:49:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for idx := range definitions {
|
|
|
|
associateExtensionData(&definitions[idx], extensions)
|
|
|
|
}
|
|
|
|
|
|
|
|
extensions = definitions
|
|
|
|
}
|
|
|
|
|
|
|
|
return response.JSON(w, extensions)
|
|
|
|
}
|
|
|
|
|
|
|
|
func associateExtensionData(definition *portainer.Extension, extensions []portainer.Extension) {
|
|
|
|
for _, extension := range extensions {
|
|
|
|
if extension.ID == definition.ID {
|
|
|
|
|
|
|
|
definition.Enabled = extension.Enabled
|
|
|
|
definition.License.Company = extension.License.Company
|
|
|
|
definition.License.Expiration = extension.License.Expiration
|
2019-01-17 21:00:18 +00:00
|
|
|
definition.License.Valid = extension.License.Valid
|
2018-12-09 03:49:27 +00:00
|
|
|
|
|
|
|
definitionVersion := semver.New(definition.Version)
|
|
|
|
extensionVersion := semver.New(extension.Version)
|
|
|
|
if extensionVersion.LessThan(*definitionVersion) {
|
|
|
|
definition.UpdateAvailable = true
|
|
|
|
}
|
|
|
|
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|