48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
package actions
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"io"
|
|
|
|
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
|
|
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/auth/scopes"
|
|
"github.com/FAU-CDI/wisski-distillery/internal/models"
|
|
"github.com/FAU-CDI/wisski-distillery/internal/wisski"
|
|
)
|
|
|
|
type Rebuild struct {
|
|
component.Base
|
|
}
|
|
|
|
var (
|
|
_ WebsocketInstanceAction = (*Rebuild)(nil)
|
|
)
|
|
|
|
func (*Rebuild) Action() InstanceAction {
|
|
return InstanceAction{
|
|
Action: Action{
|
|
Name: "rebuild",
|
|
Scope: scopes.ScopeUserAdmin,
|
|
NumParams: 1,
|
|
},
|
|
}
|
|
}
|
|
|
|
func (r *Rebuild) Act(ctx context.Context, instance *wisski.WissKI, in io.Reader, out io.Writer, params ...string) error {
|
|
// read the flags of the instance to be provisioned
|
|
var system models.System
|
|
if err := json.Unmarshal([]byte(params[0]), &system); err != nil {
|
|
return err
|
|
}
|
|
|
|
smanager := instance.SystemManager()
|
|
|
|
if err := smanager.Apply(ctx, out, system, true); err != nil {
|
|
return err
|
|
}
|
|
if err := smanager.RebuildSettings(ctx, out); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|