fix(setup): unmarshal of failed step (#7144)

This commit is contained in:
Silvan 2024-01-05 07:29:57 +01:00 committed by GitHub
parent aa2d642e97
commit 41215bdc0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,7 +2,6 @@ package migration
import (
"context"
"encoding/json"
"github.com/zitadel/zitadel/internal/api/authz"
"github.com/zitadel/zitadel/internal/api/service"
@ -15,25 +14,10 @@ type SetupStep struct {
eventstore.BaseEvent `json:"-"`
migration Migration
Name string `json:"name"`
Error error `json:"error,omitempty"`
Error string `json:"error,omitempty"`
LastRun interface{} `json:"lastRun,omitempty"`
}
func (s *SetupStep) UnmarshalJSON(data []byte) error {
fields := struct {
Name string `json:"name,"`
Error *zerrors.ZitadelError `json:"error"`
LastRun map[string]interface{} `json:"lastRun,omitempty"`
}{}
if err := json.Unmarshal(data, &fields); err != nil {
return err
}
s.Name = fields.Name
s.Error = fields.Error
s.LastRun = fields.LastRun
return nil
}
func setupStartedCmd(ctx context.Context, migration Migration) eventstore.Command {
ctx = authz.SetCtxData(service.WithService(ctx, "system"), authz.CtxData{UserID: "system", OrgID: "SYSTEM", ResourceOwner: "SYSTEM"})
return &SetupStep{
@ -54,16 +38,16 @@ func setupDoneCmd(ctx context.Context, migration Migration, err error) eventstor
typ = repeatableDoneType
lastRun = repeatable
}
if err != nil {
typ = failedType
}
s := &SetupStep{
migration: migration,
Name: migration.String(),
Error: err,
LastRun: lastRun,
}
if err != nil {
typ = failedType
s.Error = err.Error()
}
s.BaseEvent = *eventstore.NewBaseEventForPush(
ctx,