Skip to content

Commit

Permalink
Update for fabric api changes. Fixes #1295
Browse files Browse the repository at this point in the history
  • Loading branch information
plorenz committed Apr 25, 2023
1 parent 43fc1e9 commit 70008bf
Show file tree
Hide file tree
Showing 20 changed files with 128 additions and 102 deletions.
2 changes: 1 addition & 1 deletion controller/model/api_session_certificate_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (self *ApiSessionCertificateManager) newModelEntity() *ApiSessionCertificat
}

func (self *ApiSessionCertificateManager) Create(entity *ApiSessionCertificate, ctx *change.Context) (string, error) {
return self.createEntity(entity, ctx)
return self.createEntity(entity, ctx.NewMutateContext())
}

func (self *ApiSessionCertificateManager) CreateFromCSR(apiSessionId string, lifespan time.Duration, csrPem []byte, ctx *change.Context) (string, error) {
Expand Down
6 changes: 3 additions & 3 deletions controller/model/api_session_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,16 @@ func (self *ApiSessionManager) IsUpdated(_ string) bool {
}

func (self *ApiSessionManager) Update(apiSession *ApiSession, ctx *change.Context) error {
return self.updateEntity(apiSession, self, ctx)
return self.updateEntity(apiSession, self, ctx.NewMutateContext())
}

func (self *ApiSessionManager) UpdateWithFieldChecker(apiSession *ApiSession, fieldChecker boltz.FieldChecker, ctx *change.Context) error {
return self.updateEntity(apiSession, fieldChecker, ctx)
return self.updateEntity(apiSession, fieldChecker, ctx.NewMutateContext())
}

func (self *ApiSessionManager) MfaCompleted(apiSession *ApiSession, ctx *change.Context) error {
apiSession.MfaComplete = true
return self.updateEntity(apiSession, &OrFieldChecker{NewFieldChecker(persistence.FieldApiSessionMfaComplete), self}, ctx)
return self.updateEntity(apiSession, &OrFieldChecker{NewFieldChecker(persistence.FieldApiSessionMfaComplete), self}, ctx.NewMutateContext())
}

func (self *ApiSessionManager) Delete(id string, ctx *change.Context) error {
Expand Down
8 changes: 4 additions & 4 deletions controller/model/auth_policy_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (self *AuthPolicyManager) Create(entity *AuthPolicy, ctx *change.Context) e
return network.DispatchCreate[*AuthPolicy](self, entity, ctx)
}

func (self *AuthPolicyManager) ApplyCreate(cmd *command.CreateEntityCommand[*AuthPolicy]) error {
func (self *AuthPolicyManager) ApplyCreate(cmd *command.CreateEntityCommand[*AuthPolicy], ctx boltz.MutateContext) error {
entity := cmd.Entity
if entity.Secondary.RequiredExtJwtSigner != nil {
if err := self.verifyExtJwt(*entity.Secondary.RequiredExtJwtSigner, "secondary.requiredExtJwtSigner"); err != nil {
Expand All @@ -64,16 +64,16 @@ func (self *AuthPolicyManager) ApplyCreate(cmd *command.CreateEntityCommand[*Aut
}
}

_, err := self.createEntity(cmd.Entity, cmd.Context)
_, err := self.createEntity(cmd.Entity, ctx)
return err
}

func (self *AuthPolicyManager) Update(entity *AuthPolicy, checker fields.UpdatedFields, ctx *change.Context) error {
return network.DispatchUpdate[*AuthPolicy](self, entity, checker, ctx)
}

func (self *AuthPolicyManager) ApplyUpdate(cmd *command.UpdateEntityCommand[*AuthPolicy]) error {
return self.updateEntity(cmd.Entity, cmd.UpdatedFields, cmd.Context)
func (self *AuthPolicyManager) ApplyUpdate(cmd *command.UpdateEntityCommand[*AuthPolicy], ctx boltz.MutateContext) error {
return self.updateEntity(cmd.Entity, cmd.UpdatedFields, ctx)
}

func (self *AuthPolicyManager) newModelEntity() *AuthPolicy {
Expand Down
15 changes: 9 additions & 6 deletions controller/model/authenticator_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (self *AuthenticatorManager) Create(entity *Authenticator, ctx *change.Cont
return network.DispatchCreate[*Authenticator](self, entity, ctx)
}

func (self *AuthenticatorManager) ApplyCreate(cmd *command.CreateEntityCommand[*Authenticator]) error {
func (self *AuthenticatorManager) ApplyCreate(cmd *command.CreateEntityCommand[*Authenticator], ctx boltz.MutateContext) error {
authenticator := cmd.Entity
if authenticator.Method != persistence.MethodAuthenticatorUpdb && authenticator.Method != persistence.MethodAuthenticatorCert {
return errorz.NewFieldError("method must be updb or cert", "method", authenticator.Method)
Expand Down Expand Up @@ -166,7 +166,7 @@ func (self *AuthenticatorManager) ApplyCreate(cmd *command.CreateEntityCommand[*
}
}

_, err = self.createEntity(authenticator, cmd.Context)
_, err = self.createEntity(authenticator, ctx)
return err
}

Expand All @@ -183,7 +183,7 @@ func (self *AuthenticatorManager) Update(entity *Authenticator, unrestricted boo
return self.Dispatch(cmd)
}

func (self *AuthenticatorManager) ApplyUpdate(cmd *command.UpdateEntityCommand[*Authenticator]) error {
func (self *AuthenticatorManager) ApplyUpdate(cmd *command.UpdateEntityCommand[*Authenticator], ctx boltz.MutateContext) error {
authenticator := cmd.Entity
if updb := authenticator.ToUpdb(); updb != nil {
if cmd.UpdatedFields == nil || cmd.UpdatedFields.IsUpdated("password") {
Expand All @@ -209,7 +209,7 @@ func (self *AuthenticatorManager) ApplyUpdate(cmd *command.UpdateEntityCommand[*
checker = &AndFieldChecker{first: self, second: cmd.UpdatedFields}
}
}
return self.updateEntity(cmd.Entity, checker, cmd.Context)
return self.updateEntity(cmd.Entity, checker, ctx)
}

func (self *AuthenticatorManager) getRootPool() *x509.CertPool {
Expand Down Expand Up @@ -609,7 +609,11 @@ func (self *AuthenticatorManager) ReEnroll(id string, expiresAt time.Time, ctx *
return "", err
}

enrollmentId := eid.New()
enrollment := &Enrollment{
BaseEntity: models.BaseEntity{
Id: enrollmentId,
},
IdentityId: &authenticator.IdentityId,
Token: uuid.NewString(),
}
Expand Down Expand Up @@ -638,8 +642,7 @@ func (self *AuthenticatorManager) ReEnroll(id string, expiresAt time.Time, ctx *
return "", err
}

enrollmentId, err := self.env.GetManagers().Enrollment.createEntity(enrollment, ctx)
if err != nil {
if err = self.env.GetManagers().Enrollment.Create(enrollment, ctx); err != nil {
return "", err
}

Expand Down
12 changes: 6 additions & 6 deletions controller/model/base_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ func (self *baseEntityManager[ME, PE]) PreparedListAssociatedWithHandler(id stri
})
}

func (self *baseEntityManager[ME, PE]) createEntity(modelEntity edgeEntity[PE], ctx *change.Context) (string, error) {
func (self *baseEntityManager[ME, PE]) createEntity(modelEntity edgeEntity[PE], ctx boltz.MutateContext) (string, error) {
var id string
err := self.GetDb().Update(ctx.NewMutateContext(), func(ctx boltz.MutateContext) error {
err := self.GetDb().Update(ctx, func(ctx boltz.MutateContext) error {
var err error
id, err = self.createEntityInTx(ctx, modelEntity)
return err
Expand Down Expand Up @@ -198,8 +198,8 @@ func (self *baseEntityManager[ME, PE]) updateEntityBatch(modelEntity edgeEntity[
})
}

func (self *baseEntityManager[ME, PE]) updateEntity(modelEntity ME, checker boltz.FieldChecker, changeCtx *change.Context) error {
return self.GetDb().Update(changeCtx.NewMutateContext(), func(ctx boltz.MutateContext) error {
func (self *baseEntityManager[ME, PE]) updateEntity(modelEntity ME, checker boltz.FieldChecker, ctx boltz.MutateContext) error {
return self.GetDb().Update(ctx, func(ctx boltz.MutateContext) error {
existing, found, err := self.GetStore().FindById(ctx.Tx(), modelEntity.GetId())
if err != nil {
return err
Expand Down Expand Up @@ -297,8 +297,8 @@ func (self *baseEntityManager[ME, PE]) Delete(id string, ctx *change.Context) er
return self.Dispatch(cmd)
}

func (self *baseEntityManager[ME, PE]) ApplyDelete(cmd *command.DeleteEntityCommand) error {
return self.GetDb().Update(cmd.Context.NewMutateContext(), func(ctx boltz.MutateContext) error {
func (self *baseEntityManager[ME, PE]) ApplyDelete(cmd *command.DeleteEntityCommand, ctx boltz.MutateContext) error {
return self.GetDb().Update(ctx, func(ctx boltz.MutateContext) error {
return self.Store.DeleteById(ctx, cmd.Id)
})
}
Expand Down
8 changes: 4 additions & 4 deletions controller/model/ca_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ func (self *CaManager) Create(entity *Ca, ctx *change.Context) error {
return network.DispatchCreate[*Ca](self, entity, ctx)
}

func (self *CaManager) ApplyCreate(cmd *command.CreateEntityCommand[*Ca]) error {
_, err := self.createEntity(cmd.Entity, cmd.Context)
func (self *CaManager) ApplyCreate(cmd *command.CreateEntityCommand[*Ca], ctx boltz.MutateContext) error {
_, err := self.createEntity(cmd.Entity, ctx)
return err
}

Expand All @@ -67,7 +67,7 @@ func (self *CaManager) Update(entity *Ca, checker fields.UpdatedFields, ctx *cha
return network.DispatchUpdate[*Ca](self, entity, checker, ctx)
}

func (self *CaManager) ApplyUpdate(cmd *command.UpdateEntityCommand[*Ca]) error {
func (self *CaManager) ApplyUpdate(cmd *command.UpdateEntityCommand[*Ca], ctx boltz.MutateContext) error {
var checker boltz.FieldChecker = self

// isVerified should only be set by the Verified method. We remove isVerified
Expand All @@ -80,7 +80,7 @@ func (self *CaManager) ApplyUpdate(cmd *command.UpdateEntityCommand[*Ca]) error
}
}

return self.updateEntity(cmd.Entity, checker, cmd.Context)
return self.updateEntity(cmd.Entity, checker, ctx)
}

func (self *CaManager) Read(id string) (*Ca, error) {
Expand Down
8 changes: 4 additions & 4 deletions controller/model/config_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,21 @@ func (self *ConfigManager) Create(entity *Config, ctx *change.Context) error {
return network.DispatchCreate[*Config](self, entity, ctx)
}

func (self *ConfigManager) ApplyCreate(cmd *command.CreateEntityCommand[*Config]) error {
_, err := self.createEntity(cmd.Entity, cmd.Context)
func (self *ConfigManager) ApplyCreate(cmd *command.CreateEntityCommand[*Config], ctx boltz.MutateContext) error {
_, err := self.createEntity(cmd.Entity, ctx)
return err
}

func (self *ConfigManager) Update(entity *Config, checker fields.UpdatedFields, ctx *change.Context) error {
return network.DispatchUpdate[*Config](self, entity, checker, ctx)
}

func (self *ConfigManager) ApplyUpdate(cmd *command.UpdateEntityCommand[*Config]) error {
func (self *ConfigManager) ApplyUpdate(cmd *command.UpdateEntityCommand[*Config], ctx boltz.MutateContext) error {
var checker boltz.FieldChecker = self
if cmd.UpdatedFields != nil {
checker = &AndFieldChecker{first: self, second: cmd.UpdatedFields}
}
return self.updateEntity(cmd.Entity, checker, cmd.Context)
return self.updateEntity(cmd.Entity, checker, ctx)
}

func (self *ConfigManager) Read(id string) (*Config, error) {
Expand Down
9 changes: 5 additions & 4 deletions controller/model/config_type_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/openziti/fabric/controller/models"
"github.com/openziti/fabric/controller/network"
"github.com/openziti/foundation/v2/stringz"
"github.com/openziti/storage/boltz"
"go.etcd.io/bbolt"
"google.golang.org/protobuf/proto"
)
Expand Down Expand Up @@ -58,17 +59,17 @@ func (self *ConfigTypeManager) Create(entity *ConfigType, ctx *change.Context) e
return network.DispatchCreate[*ConfigType](self, entity, ctx)
}

func (self *ConfigTypeManager) ApplyCreate(cmd *command.CreateEntityCommand[*ConfigType]) error {
_, err := self.createEntity(cmd.Entity, cmd.Context)
func (self *ConfigTypeManager) ApplyCreate(cmd *command.CreateEntityCommand[*ConfigType], ctx boltz.MutateContext) error {
_, err := self.createEntity(cmd.Entity, ctx)
return err
}

func (self *ConfigTypeManager) Update(entity *ConfigType, checker fields.UpdatedFields, ctx *change.Context) error {
return network.DispatchUpdate[*ConfigType](self, entity, checker, ctx)
}

func (self *ConfigTypeManager) ApplyUpdate(cmd *command.UpdateEntityCommand[*ConfigType]) error {
return self.updateEntity(cmd.Entity, cmd.UpdatedFields, cmd.Context)
func (self *ConfigTypeManager) ApplyUpdate(cmd *command.UpdateEntityCommand[*ConfigType], ctx boltz.MutateContext) error {
return self.updateEntity(cmd.Entity, cmd.UpdatedFields, ctx)
}

func (self *ConfigTypeManager) Read(id string) (*ConfigType, error) {
Expand Down
9 changes: 6 additions & 3 deletions controller/model/create_terminator_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ type CreateEdgeTerminatorCmd struct {
Context *change.Context
}

func (self *CreateEdgeTerminatorCmd) Apply(raftIndex uint64) error {
func (self *CreateEdgeTerminatorCmd) Apply(ctx boltz.MutateContext) error {
createCmd := &command.CreateEntityCommand[*network.Terminator]{
Creator: self.Env.GetManagers().Terminator,
Entity: self.Entity,
PostCreateHook: self.validateTerminatorIdentity,
Context: self.Context,
}
createCmd.Context.RaftIndex = raftIndex
return self.Env.GetManagers().Terminator.ApplyCreate(createCmd)
return self.Env.GetManagers().Terminator.ApplyCreate(createCmd, ctx)
}

func (self *CreateEdgeTerminatorCmd) validateTerminatorIdentity(ctx boltz.MutateContext, terminator *network.Terminator) error {
Expand Down Expand Up @@ -63,6 +62,10 @@ func (self *CreateEdgeTerminatorCmd) validateTerminatorIdentity(ctx boltz.Mutate
return nil
}

func (self *CreateEdgeTerminatorCmd) GetChangeContext() *change.Context {
return self.Context
}

type terminator interface {
GetId() string
GetInstanceId() string
Expand Down
17 changes: 10 additions & 7 deletions controller/model/edge_router_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ func (self *EdgeRouterManager) Create(edgeRouter *EdgeRouter, ctx *change.Contex
return self.Dispatch(cmd)
}

func (self *EdgeRouterManager) ApplyCreate(cmd *CreateEdgeRouterCmd) error {
func (self *EdgeRouterManager) ApplyCreate(cmd *CreateEdgeRouterCmd, ctx boltz.MutateContext) error {
edgeRouter := cmd.edgeRouter
enrollment := cmd.enrollment

return self.GetDb().Update(cmd.ctx.NewMutateContext(), func(ctx boltz.MutateContext) error {
return self.GetDb().Update(ctx, func(ctx boltz.MutateContext) error {
boltEdgeRouter, err := edgeRouter.toBoltEntityForCreate(ctx.Tx(), self.env)
if err != nil {
return err
Expand Down Expand Up @@ -138,7 +138,7 @@ func (self *EdgeRouterManager) Update(entity *EdgeRouter, unrestricted bool, che
return self.Dispatch(cmd)
}

func (self *EdgeRouterManager) ApplyUpdate(cmd *command.UpdateEntityCommand[*EdgeRouter]) error {
func (self *EdgeRouterManager) ApplyUpdate(cmd *command.UpdateEntityCommand[*EdgeRouter], ctx boltz.MutateContext) error {
var checker boltz.FieldChecker = cmd.UpdatedFields
if cmd.Flags != updateUnrestricted {
if checker == nil {
Expand All @@ -147,7 +147,7 @@ func (self *EdgeRouterManager) ApplyUpdate(cmd *command.UpdateEntityCommand[*Edg
checker = &AndFieldChecker{first: self.allowedFieldsChecker, second: cmd.UpdatedFields}
}
}
return self.updateEntity(cmd.Entity, checker, cmd.Context)
return self.updateEntity(cmd.Entity, checker, ctx)
}

func (self *EdgeRouterManager) Read(id string) (*EdgeRouter, error) {
Expand Down Expand Up @@ -557,9 +557,8 @@ type CreateEdgeRouterCmd struct {
ctx *change.Context
}

func (self *CreateEdgeRouterCmd) Apply(raftIndex uint64) error {
self.ctx.RaftIndex = raftIndex
return self.manager.ApplyCreate(self)
func (self *CreateEdgeRouterCmd) Apply(ctx boltz.MutateContext) error {
return self.manager.ApplyCreate(self, ctx)
}

func (self *CreateEdgeRouterCmd) Encode() ([]byte, error) {
Expand Down Expand Up @@ -600,3 +599,7 @@ func (self *CreateEdgeRouterCmd) Decode(env Env, msg *edge_cmd_pb.CreateEdgeRout

return nil
}

func (self *CreateEdgeRouterCmd) GetChangeContext() *change.Context {
return self.ctx
}
9 changes: 5 additions & 4 deletions controller/model/edge_router_policy_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/openziti/fabric/controller/fields"
"github.com/openziti/fabric/controller/models"
"github.com/openziti/fabric/controller/network"
"github.com/openziti/storage/boltz"
"google.golang.org/protobuf/proto"
)

Expand All @@ -50,17 +51,17 @@ func (self *EdgeRouterPolicyManager) Create(entity *EdgeRouterPolicy, ctx *chang
return network.DispatchCreate[*EdgeRouterPolicy](self, entity, ctx)
}

func (self *EdgeRouterPolicyManager) ApplyCreate(cmd *command.CreateEntityCommand[*EdgeRouterPolicy]) error {
_, err := self.createEntity(cmd.Entity, cmd.Context)
func (self *EdgeRouterPolicyManager) ApplyCreate(cmd *command.CreateEntityCommand[*EdgeRouterPolicy], ctx boltz.MutateContext) error {
_, err := self.createEntity(cmd.Entity, ctx)
return err
}

func (self *EdgeRouterPolicyManager) Update(entity *EdgeRouterPolicy, checker fields.UpdatedFields, ctx *change.Context) error {
return network.DispatchUpdate[*EdgeRouterPolicy](self, entity, checker, ctx)
}

func (self *EdgeRouterPolicyManager) ApplyUpdate(cmd *command.UpdateEntityCommand[*EdgeRouterPolicy]) error {
return self.updateEntity(cmd.Entity, cmd.UpdatedFields, cmd.Context)
func (self *EdgeRouterPolicyManager) ApplyUpdate(cmd *command.UpdateEntityCommand[*EdgeRouterPolicy], ctx boltz.MutateContext) error {
return self.updateEntity(cmd.Entity, cmd.UpdatedFields, ctx)
}

func (self *EdgeRouterPolicyManager) Marshall(entity *EdgeRouterPolicy) ([]byte, error) {
Expand Down
8 changes: 4 additions & 4 deletions controller/model/edge_service_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ func (self *EdgeServiceManager) Create(entity *Service, ctx *change.Context) err
return network.DispatchCreate[*Service](self, entity, ctx)
}

func (self *EdgeServiceManager) ApplyCreate(cmd *command.CreateEntityCommand[*Service]) error {
_, err := self.createEntity(cmd.Entity, cmd.Context)
func (self *EdgeServiceManager) ApplyCreate(cmd *command.CreateEntityCommand[*Service], ctx boltz.MutateContext) error {
_, err := self.createEntity(cmd.Entity, ctx)
return err
}

Expand All @@ -78,8 +78,8 @@ func (self *EdgeServiceManager) Update(entity *Service, checker fields.UpdatedFi
return network.DispatchUpdate[*Service](self, entity, checker, ctx)
}

func (self *EdgeServiceManager) ApplyUpdate(cmd *command.UpdateEntityCommand[*Service]) error {
return self.updateEntity(cmd.Entity, cmd.UpdatedFields, cmd.Context)
func (self *EdgeServiceManager) ApplyUpdate(cmd *command.UpdateEntityCommand[*Service], ctx boltz.MutateContext) error {
return self.updateEntity(cmd.Entity, cmd.UpdatedFields, ctx)
}

func (self *EdgeServiceManager) ReadByName(name string) (*Service, error) {
Expand Down
Loading

0 comments on commit 70008bf

Please sign in to comment.