1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-08-04 05:15:25 +02:00

feat(system): path to upgrade standalone to BE [EE-4071] (#8095)

This commit is contained in:
Chaim Lev-Ari 2022-12-11 08:58:22 +02:00 committed by GitHub
parent 756ac034ec
commit 5cbf52377d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
73 changed files with 1374 additions and 421 deletions

View file

@ -0,0 +1,54 @@
package system
import (
"net/http"
"regexp"
"github.com/pkg/errors"
httperror "github.com/portainer/libhttp/error"
"github.com/portainer/libhttp/request"
"github.com/portainer/libhttp/response"
"github.com/rs/zerolog/log"
)
type systemUpgradePayload struct {
License string
}
var re = regexp.MustCompile(`^\d-.+`)
func (payload *systemUpgradePayload) Validate(r *http.Request) error {
if payload.License == "" {
return errors.New("license is missing")
}
if !re.MatchString(payload.License) {
return errors.New("license is invalid")
}
return nil
}
// @id systemUpgrade
// @summary Upgrade Portainer to BE
// @description Upgrade Portainer to BE
// @description **Access policy**: administrator
// @tags system
// @produce json
// @success 200 {object} status "Success"
// @router /system/upgrade [post]
func (handler *Handler) systemUpgrade(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
payload, err := request.GetPayload[systemUpgradePayload](r)
if err != nil {
return httperror.BadRequest("Invalid request payload", err)
}
go func() {
err = handler.upgradeService.Upgrade(payload.License)
if err != nil {
log.Error().Err(err).Msg("Failed to upgrade Portainer")
}
}()
return response.Empty(w)
}