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:
parent
756ac034ec
commit
5cbf52377d
73 changed files with 1374 additions and 421 deletions
54
api/http/handler/system/system_upgrade.go
Normal file
54
api/http/handler/system/system_upgrade.go
Normal 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)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue