diff --git a/controller/db/api_session_store.go b/controller/db/api_session_store.go index 52e6c4b95..cf427bb38 100644 --- a/controller/db/api_session_store.go +++ b/controller/db/api_session_store.go @@ -257,7 +257,7 @@ func (store *apiSessionStoreImpl) initializeLinked() { func (store *apiSessionStoreImpl) LoadOneByToken(tx *bbolt.Tx, token string) (*ApiSession, error) { id := store.indexToken.Read(tx, []byte(token)) if id != nil { - return store.LoadOneById(tx, string(id)) + return store.LoadById(tx, string(id)) } return nil, boltz.NewNotFoundError(store.GetSingularEntityType(), "token", token) } diff --git a/controller/db/api_session_store_test.go b/controller/db/api_session_store_test.go index 34fa8db7c..7430842c8 100644 --- a/controller/db/api_session_store_test.go +++ b/controller/db/api_session_store_test.go @@ -178,11 +178,11 @@ func (ctx *TestContext) testUpdateApiSessions(t *testing.T) { mutateCtx := change.New().NewMutateContext() err := ctx.GetDb().Update(mutateCtx, func(mutateCtx boltz.MutateContext) error { tx := mutateCtx.Tx() - original, err := ctx.stores.ApiSession.LoadOneById(tx, entities.apiSession1.Id) + original, err := ctx.stores.ApiSession.LoadById(tx, entities.apiSession1.Id) ctx.NoError(err) ctx.NotNil(original) - apiSession, err := ctx.stores.ApiSession.LoadOneById(tx, entities.apiSession1.Id) + apiSession, err := ctx.stores.ApiSession.LoadById(tx, entities.apiSession1.Id) ctx.NoError(err) ctx.NotNil(apiSession) @@ -196,7 +196,7 @@ func (ctx *TestContext) testUpdateApiSessions(t *testing.T) { err = ctx.stores.ApiSession.Update(mutateCtx, apiSession, nil) ctx.NoError(err) - loaded, err := ctx.stores.ApiSession.LoadOneById(tx, entities.apiSession1.Id) + loaded, err := ctx.stores.ApiSession.LoadById(tx, entities.apiSession1.Id) ctx.NoError(err) ctx.NotNil(loaded) ctx.EqualValues(original.CreatedAt, loaded.CreatedAt) diff --git a/controller/db/base_store.go b/controller/db/base_store.go index dde2c136a..f9cc01005 100644 --- a/controller/db/base_store.go +++ b/controller/db/base_store.go @@ -34,7 +34,6 @@ type initializableStore interface { type Store[E boltz.ExtEntity] interface { boltz.EntityStore[E] initializableStore - LoadOneById(tx *bbolt.Tx, id string) (E, error) } type baseStore[E boltz.ExtEntity] struct { @@ -51,25 +50,6 @@ func (store *baseStore[E]) initializeIndexes(tx *bbolt.Tx, errorHolder errorz.Er store.InitializeIndexes(tx, errorHolder) } -func (store *baseStore[E]) LoadOneById(tx *bbolt.Tx, id string) (E, error) { - entity := store.NewStoreEntity() - if err := store.baseLoadOneById(tx, id, entity); err != nil { - return *new(E), err - } - return entity, nil -} - -func (store *baseStore[E]) baseLoadOneById(tx *bbolt.Tx, id string, entity E) error { - found, err := store.LoadEntity(tx, id, entity) - if err != nil { - return err - } - if !found { - return boltz.NewNotFoundError(store.GetSingularEntityType(), "id", id) - } - return nil -} - func (store *baseStore[E]) deleteEntityReferences(tx *bbolt.Tx, entity boltz.NamedExtEntity, rolesSymbol boltz.EntitySetSymbol) error { idRef := entityRef(entity.GetId()) diff --git a/controller/db/config_store_test.go b/controller/db/config_store_test.go index c61fbc8af..d928322f5 100644 --- a/controller/db/config_store_test.go +++ b/controller/db/config_store_test.go @@ -64,7 +64,7 @@ func (ctx *TestContext) testConfigCrud(*testing.T) { boltztest.ValidateBaseline(ctx, config) err = ctx.GetDb().View(func(tx *bbolt.Tx) error { - testConfig, err := ctx.stores.Config.LoadOneById(tx, config.Id) + testConfig, err := ctx.stores.Config.LoadById(tx, config.Id) ctx.NoError(err) ctx.NotNil(testConfig) ctx.Equal(config.Name, testConfig.Name) diff --git a/controller/db/config_type_store.go b/controller/db/config_type_store.go index 56345f14f..526119b10 100644 --- a/controller/db/config_type_store.go +++ b/controller/db/config_type_store.go @@ -120,7 +120,7 @@ func (store *configTypeStoreImpl) PersistEntity(entity *ConfigType, ctx *boltz.P func (store *configTypeStoreImpl) LoadOneByName(tx *bbolt.Tx, name string) (*ConfigType, error) { id := store.indexName.Read(tx, []byte(name)) if id != nil { - return store.LoadOneById(tx, string(id)) + return store.LoadById(tx, string(id)) } return nil, nil } diff --git a/controller/db/edge_router_policy_store.go b/controller/db/edge_router_policy_store.go index b1cb6a14a..0c4d9432b 100644 --- a/controller/db/edge_router_policy_store.go +++ b/controller/db/edge_router_policy_store.go @@ -164,7 +164,7 @@ func (store *edgeRouterPolicyStoreImpl) identityRolesUpdated(persistCtx *boltz.P } func (store *edgeRouterPolicyStoreImpl) DeleteById(ctx boltz.MutateContext, id string) error { - policy, err := store.LoadOneById(ctx.Tx(), id) + policy, err := store.LoadById(ctx.Tx(), id) if err != nil { return err } diff --git a/controller/db/edge_router_policy_store_test.go b/controller/db/edge_router_policy_store_test.go index b5d55c216..015760591 100644 --- a/controller/db/edge_router_policy_store_test.go +++ b/controller/db/edge_router_policy_store_test.go @@ -38,7 +38,7 @@ func (ctx *TestContext) testCreateEdgeRouterPolicy(t *testing.T) { ctx.Equal(0, len(ctx.stores.EdgeRouterPolicy.GetRelatedEntitiesIdList(tx, policy.Id, EntityTypeRouters))) ctx.Equal(0, len(ctx.stores.EdgeRouterPolicy.GetRelatedEntitiesIdList(tx, policy.Id, EntityTypeIdentities))) - testPolicy, err := ctx.stores.EdgeRouterPolicy.LoadOneById(tx, policy.Id) + testPolicy, err := ctx.stores.EdgeRouterPolicy.LoadById(tx, policy.Id) ctx.NoError(err) ctx.NotNil(testPolicy) ctx.Equal(policy.Name, testPolicy.Name) diff --git a/controller/db/edge_router_store.go b/controller/db/edge_router_store.go index a35ebbc0e..7505e333e 100644 --- a/controller/db/edge_router_store.go +++ b/controller/db/edge_router_store.go @@ -231,7 +231,7 @@ func (store *edgeRouterStoreImpl) GetNameIndex() boltz.ReadIndex { } func (store *edgeRouterStoreImpl) cleanupEdgeRouter(ctx boltz.MutateContext, id string) error { - if entity, _ := store.LoadOneById(ctx.Tx(), id); entity != nil { + if entity, _ := store.LoadById(ctx.Tx(), id); entity != nil { // Remove entity from EdgeRouterRoles in edge router policies if err := store.deleteEntityReferences(ctx.Tx(), entity, store.stores.edgeRouterPolicy.symbolEdgeRouterRoles); err != nil { return err @@ -311,7 +311,7 @@ func (self *routerIdentityConstraint) ProcessAfterUpdate(ctx *boltz.IndexingCont } if !createEntities && currentTunnelerEnabled && oldName != name { - identity, err := self.stores.identity.LoadOneById(ctx.Tx(), routerId) + identity, err := self.stores.identity.LoadById(ctx.Tx(), routerId) if err != nil { if boltz.IsErrNotFoundErr(err) { logrus.Errorf("identity for router with id %v not found", routerId) diff --git a/controller/db/edge_service_store.go b/controller/db/edge_service_store.go index 968f5726c..50242bad5 100644 --- a/controller/db/edge_service_store.go +++ b/controller/db/edge_service_store.go @@ -251,7 +251,7 @@ func (store *edgeServiceStoreImpl) Update(ctx boltz.MutateContext, entity *EdgeS } func (store *edgeServiceStoreImpl) cleanupEdgeService(ctx boltz.MutateContext, id string) error { - if entity, _ := store.LoadOneById(ctx.Tx(), id); entity != nil { + if entity, _ := store.LoadById(ctx.Tx(), id); entity != nil { // Remove entity from ServiceRoles in service policies if err := store.deleteEntityReferences(ctx.Tx(), entity, store.stores.servicePolicy.symbolServiceRoles); err != nil { return err diff --git a/controller/db/edge_service_store_test.go b/controller/db/edge_service_store_test.go index 45a9c05e0..8946d1b00 100644 --- a/controller/db/edge_service_store_test.go +++ b/controller/db/edge_service_store_test.go @@ -181,7 +181,7 @@ func (ctx *TestContext) testLoadQueryEdgeServices(_ *testing.T) { entities := ctx.createEdgeServiceTestEntities() err := ctx.GetDb().View(func(tx *bbolt.Tx) error { - service, err := ctx.stores.EdgeService.LoadOneById(tx, entities.service1.Id) + service, err := ctx.stores.EdgeService.LoadById(tx, entities.service1.Id) ctx.NoError(err) ctx.NotNil(service) ctx.EqualValues(entities.service1.Id, service.Id) @@ -217,11 +217,11 @@ func (ctx *TestContext) testUpdateEdgeServices(_ *testing.T) { mutateCtx := change.New().NewMutateContext() err := ctx.GetDb().Update(mutateCtx, func(mutateCtx boltz.MutateContext) error { tx := mutateCtx.Tx() - original, err := ctx.stores.EdgeService.LoadOneById(tx, entities.service1.Id) + original, err := ctx.stores.EdgeService.LoadById(tx, entities.service1.Id) ctx.NoError(err) ctx.NotNil(original) - service, err := ctx.stores.EdgeService.LoadOneById(tx, entities.service1.Id) + service, err := ctx.stores.EdgeService.LoadById(tx, entities.service1.Id) ctx.NoError(err) ctx.NotNil(service) @@ -234,7 +234,7 @@ func (ctx *TestContext) testUpdateEdgeServices(_ *testing.T) { err = ctx.stores.EdgeService.Update(mutateCtx, service, nil) ctx.NoError(err) - loaded, err := ctx.stores.EdgeService.LoadOneById(tx, entities.service1.Id) + loaded, err := ctx.stores.EdgeService.LoadById(tx, entities.service1.Id) ctx.NoError(err) ctx.NotNil(loaded) ctx.EqualValues(original.CreatedAt, loaded.CreatedAt) diff --git a/controller/db/enrollment_store.go b/controller/db/enrollment_store.go index 06a5ad9e9..0f8ff4238 100644 --- a/controller/db/enrollment_store.go +++ b/controller/db/enrollment_store.go @@ -142,7 +142,7 @@ func (store *enrollmentStoreImpl) PersistEntity(entity *Enrollment, ctx *boltz.P func (store *enrollmentStoreImpl) LoadOneByToken(tx *bbolt.Tx, token string) (*Enrollment, error) { id := store.tokenIndex.Read(tx, []byte(token)) if id != nil { - return store.LoadOneById(tx, string(id)) + return store.LoadById(tx, string(id)) } return nil, nil } diff --git a/controller/db/eventual_eventer.go b/controller/db/eventual_eventer.go index 805853bad..ba19cd545 100644 --- a/controller/db/eventual_eventer.go +++ b/controller/db/eventual_eventer.go @@ -489,7 +489,7 @@ func (a *EventualEventerBbolt) getEventualEvents() ([]string, []*EventualEvent, } for _, id := range ids { - event, err := a.store.LoadOneById(tx, id) + event, err := a.store.LoadById(tx, id) if err != nil { pfxlog.Logger().WithField("id", id).WithError(err).Errorf("error could not load event id %s", id) diff --git a/controller/db/identity_store.go b/controller/db/identity_store.go index be12570f5..f7be28f40 100644 --- a/controller/db/identity_store.go +++ b/controller/db/identity_store.go @@ -400,7 +400,7 @@ func (store *identityStoreImpl) DeleteById(ctx boltz.MutateContext, id string) e } } - if entity, _ := store.LoadOneById(ctx.Tx(), id); entity != nil { + if entity, _ := store.LoadById(ctx.Tx(), id); entity != nil { if entity.IsDefaultAdmin { return errorz.NewEntityCanNotBeDeleted() } @@ -444,7 +444,7 @@ func (store *identityStoreImpl) AssignServiceConfigs(tx *bbolt.Tx, identityId st } configTypes := map[string]struct{}{} for _, serviceConfig := range serviceConfigs { - config, err := store.stores.config.LoadOneById(tx, serviceConfig.ConfigId) + config, err := store.stores.config.LoadById(tx, serviceConfig.ConfigId) if err != nil { return err } @@ -625,7 +625,7 @@ func (store *identityStoreImpl) LoadServiceConfigsByServiceAndType(tx *bbolt.Tx, _, wantsType = configTypes[configTypeId] } if wantsType { - if config, _ := store.stores.config.LoadOneById(tx, configId); config != nil { + if config, _ := store.stores.config.LoadById(tx, configId); config != nil { serviceMap, ok := result[serviceId] if !ok { serviceMap = map[string]map[string]interface{}{} diff --git a/controller/db/migration_v16.go b/controller/db/migration_v16.go index 1e5b00193..7c6b7375f 100644 --- a/controller/db/migration_v16.go +++ b/controller/db/migration_v16.go @@ -15,7 +15,7 @@ func (m *Migrations) removeOrphanedOttCaEnrollments(step *boltz.MigrationStep) { current := cursor.Current() currentEnrollmentId := string(current) - enrollment, err := m.stores.Enrollment.LoadOneById(step.Ctx.Tx(), currentEnrollmentId) + enrollment, err := m.stores.Enrollment.LoadById(step.Ctx.Tx(), currentEnrollmentId) if err != nil { step.SetError(fmt.Errorf("error iterating ids of enrollments, enrollment [%s]: %v", currentEnrollmentId, err)) @@ -23,7 +23,7 @@ func (m *Migrations) removeOrphanedOttCaEnrollments(step *boltz.MigrationStep) { } if enrollment.CaId != nil && *enrollment.CaId != "" { - _, err := m.stores.Ca.LoadOneById(step.Ctx.Tx(), *enrollment.CaId) + _, err := m.stores.Ca.LoadById(step.Ctx.Tx(), *enrollment.CaId) if err != nil && boltz.IsErrNotFoundErr(err) { enrollmentsToDelete = append(enrollmentsToDelete, currentEnrollmentId) diff --git a/controller/db/migration_v18.go b/controller/db/migration_v18.go index d99b96ed3..c63eb6c97 100644 --- a/controller/db/migration_v18.go +++ b/controller/db/migration_v18.go @@ -8,7 +8,7 @@ import ( // Primes API Session's lastActivityAt proper to their previous updatedAt value func (m *Migrations) setLastActivityAt(step *boltz.MigrationStep) { for cursor := m.stores.ApiSession.IterateIds(step.Ctx.Tx(), ast.BoolNodeTrue); cursor.IsValid(); cursor.Next() { - if apiSession, err := m.stores.ApiSession.LoadOneById(step.Ctx.Tx(), string(cursor.Current())); err == nil { + if apiSession, err := m.stores.ApiSession.LoadById(step.Ctx.Tx(), string(cursor.Current())); err == nil { apiSession.LastActivityAt = apiSession.UpdatedAt step.SetError(m.stores.ApiSession.Update(step.Ctx, apiSession, UpdateLastActivityAtChecker{})) } else { diff --git a/controller/db/migration_v19.go b/controller/db/migration_v19.go index 189665ecf..a2eecd878 100644 --- a/controller/db/migration_v19.go +++ b/controller/db/migration_v19.go @@ -35,7 +35,7 @@ func (m *Migrations) updateIdentityTypes(step *boltz.MigrationStep) { for cursor := identityStore.IterateIds(step.Ctx.Tx(), ast.BoolNodeTrue); cursor.IsValid(); cursor.Next() { current := cursor.Current() - identity, err := identityStore.LoadOneById(step.Ctx.Tx(), string(current)) + identity, err := identityStore.LoadById(step.Ctx.Tx(), string(current)) if step.SetError(err) { return } @@ -64,7 +64,7 @@ func (m *Migrations) updateIdentityTypes(step *boltz.MigrationStep) { } func (m *Migrations) migrateIdentityType(step *boltz.MigrationStep, id string) { - idType, err := m.stores.IdentityType.LoadOneById(step.Ctx.Tx(), id) + idType, err := m.stores.IdentityType.LoadById(step.Ctx.Tx(), id) if step.SetError(err) { return } diff --git a/controller/db/migration_v24.go b/controller/db/migration_v24.go index a043c2af2..32c79af5c 100644 --- a/controller/db/migration_v24.go +++ b/controller/db/migration_v24.go @@ -15,7 +15,7 @@ func (m *Migrations) addIdentityIdToSessions(step *boltz.MigrationStep) { for cursor.IsValid() { sessionId := string(cursor.Current()) - session, err := m.stores.Session.LoadOneById(step.Ctx.Tx(), sessionId) + session, err := m.stores.Session.LoadById(step.Ctx.Tx(), sessionId) if err != nil { step.SetError(fmt.Errorf("could no load session by id [%s]: %v", sessionId, err)) @@ -28,7 +28,7 @@ func (m *Migrations) addIdentityIdToSessions(step *boltz.MigrationStep) { } if session.IdentityId == "" { - if apiSession, err := m.stores.ApiSession.LoadOneById(step.Ctx.Tx(), session.ApiSessionId); err == nil { + if apiSession, err := m.stores.ApiSession.LoadById(step.Ctx.Tx(), session.ApiSessionId); err == nil { if apiSession != nil { session.IdentityId = apiSession.IdentityId if err = m.stores.Session.Update(step.Ctx, session, fieldChecker); err != nil { diff --git a/controller/db/policy_common.go b/controller/db/policy_common.go index 7607d3ac9..0a89f9f41 100644 --- a/controller/db/policy_common.go +++ b/controller/db/policy_common.go @@ -1,7 +1,6 @@ package db import ( - "bytes" "fmt" "github.com/michaelquigley/pfxlog" "github.com/openziti/foundation/v2/errorz" @@ -311,24 +310,36 @@ type denormCheckCtx struct { func validatePolicyDenormalization(ctx *denormCheckCtx) error { tx := ctx.mutateCtx.Tx() + + links := map[string]map[string]int{} + + for policyCursor := ctx.policyStore.IterateIds(tx, ast.BoolNodeTrue); policyCursor.IsValid(); policyCursor.Next() { + policyId := policyCursor.Current() + if ctx.policyFilter == nil || ctx.policyFilter(policyId) { + for sourceCursor := ctx.sourceCollection.IterateLinks(tx, policyId); sourceCursor.IsValid(); sourceCursor.Next() { + sourceId := string(sourceCursor.Current()) + for destCursor := ctx.targetCollection.IterateLinks(tx, policyId); destCursor.IsValid(); destCursor.Next() { + destId := string(destCursor.Current()) + destMap := links[sourceId] + if destMap == nil { + destMap = map[string]int{} + links[sourceId] = destMap + } + destMap[destId] = destMap[destId] + 1 + } + } + } + } + for sourceCursor := ctx.sourceStore.IterateIds(tx, ast.BoolNodeTrue); sourceCursor.IsValid(); sourceCursor.Next() { sourceEntityId := sourceCursor.Current() for targetCursor := ctx.targetStore.IterateIds(tx, ast.BoolNodeTrue); targetCursor.IsValid(); targetCursor.Next() { targetEntityId := targetCursor.Current() - var relatedPolicies []string - - for policyCursor := ctx.policyStore.IterateIds(tx, ast.BoolNodeTrue); policyCursor.IsValid(); policyCursor.Next() { - policyId := policyCursor.Current() - if ctx.policyFilter == nil || ctx.policyFilter(policyId) { - sourceRelated := isRelatedByLinkCollection(tx, ctx.sourceCollection, policyId, sourceEntityId) - targetRelated := isRelatedByLinkCollection(tx, ctx.targetCollection, policyId, targetEntityId) - if sourceRelated && targetRelated { - relatedPolicies = append(relatedPolicies, string(policyId)) - } - } + linkCount := 0 + if destMap, ok := links[string(sourceEntityId)]; ok { + linkCount = destMap[string(targetEntityId)] } - linkCount := len(relatedPolicies) var sourceLinkCount, targetLinkCount *int32 var err error if ctx.repair { @@ -367,9 +378,3 @@ func logDiscrepencies(ctx *denormCheckCtx, count int, sourceId, targetId []byte, ctx.errorSink(err, ctx.repair) } } - -func isRelatedByLinkCollection(tx *bbolt.Tx, linkCollection boltz.LinkCollection, entityId, relatedId []byte) bool { - cursor := linkCollection.IterateLinks(tx, entityId) - cursor.Seek(relatedId) - return bytes.Equal(cursor.Current(), relatedId) -} diff --git a/controller/db/posture_check_store.go b/controller/db/posture_check_store.go index 8e8890e6f..eb15b4cbd 100644 --- a/controller/db/posture_check_store.go +++ b/controller/db/posture_check_store.go @@ -83,7 +83,6 @@ func (entity *PostureCheck) GetEntityType() string { type PostureCheckStore interface { Store[*PostureCheck] - LoadOneById(tx *bbolt.Tx, id string) (*PostureCheck, error) GetRoleAttributesIndex() boltz.SetReadIndex GetRoleAttributesCursorProvider(filters []string, semantic string) (ast.SetCursorProvider, error) } @@ -180,7 +179,7 @@ func (store *postureCheckStoreImpl) GetNameIndex() boltz.ReadIndex { } func (store *postureCheckStoreImpl) DeleteById(ctx boltz.MutateContext, id string) error { - if entity, _ := store.LoadOneById(ctx.Tx(), id); entity != nil { + if entity, _ := store.LoadById(ctx.Tx(), id); entity != nil { // Remove entity from PostureCheckRoles in service policies if err := store.deleteEntityReferences(ctx.Tx(), entity, store.stores.servicePolicy.symbolPostureCheckRoles); err != nil { return err diff --git a/controller/db/service_edge_router_policy_store.go b/controller/db/service_edge_router_policy_store.go index 28ddf12cc..8d4ce9c00 100644 --- a/controller/db/service_edge_router_policy_store.go +++ b/controller/db/service_edge_router_policy_store.go @@ -163,7 +163,7 @@ func (store *serviceEdgeRouterPolicyStoreImpl) serviceRolesUpdated(persistCtx *b } func (store *serviceEdgeRouterPolicyStoreImpl) DeleteById(ctx boltz.MutateContext, id string) error { - policy, err := store.LoadOneById(ctx.Tx(), id) + policy, err := store.LoadById(ctx.Tx(), id) if err != nil { return err } diff --git a/controller/db/service_edge_router_policy_store_test.go b/controller/db/service_edge_router_policy_store_test.go index 8af741bf0..d33dfa2b7 100644 --- a/controller/db/service_edge_router_policy_store_test.go +++ b/controller/db/service_edge_router_policy_store_test.go @@ -33,7 +33,7 @@ func (ctx *TestContext) testCreateServiceEdgeRouterPolicy(_ *testing.T) { ctx.Equal(0, len(ctx.stores.ServiceEdgeRouterPolicy.GetRelatedEntitiesIdList(tx, policy.Id, EntityTypeRouters))) ctx.Equal(0, len(ctx.stores.ServiceEdgeRouterPolicy.GetRelatedEntitiesIdList(tx, policy.Id, EntityTypeServices))) - testPolicy, err := ctx.stores.ServiceEdgeRouterPolicy.LoadOneById(tx, policy.Id) + testPolicy, err := ctx.stores.ServiceEdgeRouterPolicy.LoadById(tx, policy.Id) ctx.NoError(err) ctx.NotNil(testPolicy) ctx.Equal(policy.Name, testPolicy.Name) diff --git a/controller/db/service_policy_store.go b/controller/db/service_policy_store.go index 28c70e185..7e67b6009 100644 --- a/controller/db/service_policy_store.go +++ b/controller/db/service_policy_store.go @@ -274,7 +274,7 @@ func (store *servicePolicyStoreImpl) postureCheckRolesUpdated(persistCtx *boltz. } func (store *servicePolicyStoreImpl) DeleteById(ctx boltz.MutateContext, id string) error { - policy, err := store.LoadOneById(ctx.Tx(), id) + policy, err := store.LoadById(ctx.Tx(), id) if err != nil { return err } diff --git a/controller/db/service_policy_store_test.go b/controller/db/service_policy_store_test.go index 87e170a79..1f26a7990 100644 --- a/controller/db/service_policy_store_test.go +++ b/controller/db/service_policy_store_test.go @@ -49,7 +49,7 @@ func (ctx *TestContext) testCreateServicePolicy(_ *testing.T) { ctx.Equal(0, len(ctx.stores.ServicePolicy.GetRelatedEntitiesIdList(tx, policy.Id, EntityTypeServices))) ctx.Equal(0, len(ctx.stores.ServicePolicy.GetRelatedEntitiesIdList(tx, policy.Id, EntityTypeIdentities))) - testPolicy, err := ctx.stores.ServicePolicy.LoadOneById(tx, policy.Id) + testPolicy, err := ctx.stores.ServicePolicy.LoadById(tx, policy.Id) ctx.NoError(err) ctx.NotNil(testPolicy) ctx.Equal(policy.Name, testPolicy.Name) diff --git a/controller/db/session_store.go b/controller/db/session_store.go index c24689275..57f8fbcf4 100644 --- a/controller/db/session_store.go +++ b/controller/db/session_store.go @@ -145,14 +145,14 @@ func (*sessionStoreImpl) PersistEntity(entity *Session, ctx *boltz.PersistContex ctx.SetStringList(FieldSessionServicePolicies, entity.ServicePolicies) if entity.ApiSession == nil { - entity.ApiSession, _ = ctx.Store.(*sessionStoreImpl).stores.apiSession.LoadOneById(ctx.Bucket.Tx(), entity.ApiSessionId) + entity.ApiSession, _ = ctx.Store.(*sessionStoreImpl).stores.apiSession.LoadById(ctx.Bucket.Tx(), entity.ApiSessionId) } } func (store *sessionStoreImpl) LoadOneByToken(tx *bbolt.Tx, token string) (*Session, error) { id := store.indexToken.Read(tx, []byte(token)) if id != nil { - return store.LoadOneById(tx, string(id)) + return store.LoadById(tx, string(id)) } return nil, boltz.NewNotFoundError(store.GetSingularEntityType(), "token", token) } diff --git a/controller/db/session_store_test.go b/controller/db/session_store_test.go index 8cea0cca2..c6dc3264c 100644 --- a/controller/db/session_store_test.go +++ b/controller/db/session_store_test.go @@ -100,7 +100,7 @@ func (ctx *TestContext) testUpdateInvalidSessions(_ *testing.T) { boltztest.RequireUpdate(ctx, session) err := ctx.GetDb().View(func(tx *bbolt.Tx) error { - loaded, err := ctx.stores.Session.LoadOneById(tx, session.Id) + loaded, err := ctx.stores.Session.LoadById(tx, session.Id) ctx.NoError(err) ctx.NotNil(loaded) ctx.Equal(apiSession.Id, loaded.ApiSessionId) @@ -236,11 +236,11 @@ func (ctx *TestContext) testUpdateSessions(_ *testing.T) { mutateCtx := change.New().NewMutateContext() err := ctx.GetDb().Update(mutateCtx, func(mutateCtx boltz.MutateContext) error { tx := mutateCtx.Tx() - original, err := ctx.stores.Session.LoadOneById(tx, entities.session1.Id) + original, err := ctx.stores.Session.LoadById(tx, entities.session1.Id) ctx.NoError(err) ctx.NotNil(original) - session, err := ctx.stores.Session.LoadOneById(tx, entities.session1.Id) + session, err := ctx.stores.Session.LoadById(tx, entities.session1.Id) ctx.NoError(err) ctx.NotNil(session) @@ -252,7 +252,7 @@ func (ctx *TestContext) testUpdateSessions(_ *testing.T) { err = ctx.stores.Session.Update(mutateCtx, session, nil) ctx.NoError(err) - loaded, err := ctx.stores.Session.LoadOneById(tx, entities.session1.Id) + loaded, err := ctx.stores.Session.LoadById(tx, entities.session1.Id) ctx.NoError(err) ctx.NotNil(loaded) ctx.EqualValues(original.CreatedAt, loaded.CreatedAt) diff --git a/controller/db/transit_router_store.go b/controller/db/transit_router_store.go index 8ede0de8b..9796e0fe2 100644 --- a/controller/db/transit_router_store.go +++ b/controller/db/transit_router_store.go @@ -133,7 +133,7 @@ func (store *transitRouterStoreImpl) PersistEntity(entity *TransitRouter, ctx *b } func (store *transitRouterStoreImpl) cleanupEnrollments(ctx boltz.MutateContext, id string) error { - if entity, _ := store.LoadOneById(ctx.Tx(), id); entity != nil { + if entity, _ := store.LoadById(ctx.Tx(), id); entity != nil { // Remove outstanding enrollments if err := store.stores.enrollment.DeleteWhere(ctx, fmt.Sprintf(`transitRouter="%s"`, entity.Id)); err != nil { return err diff --git a/controller/env/broker.go b/controller/env/broker.go index e92479562..162c8d187 100644 --- a/controller/env/broker.go +++ b/controller/env/broker.go @@ -159,7 +159,7 @@ func (broker *Broker) apiSessionCertificateHandler(delete bool, apiSessionCert * var apiSession *db.ApiSession var err error err = broker.ae.GetDbProvider().GetDb().View(func(tx *bbolt.Tx) error { - apiSession, err = broker.ae.GetStores().ApiSession.LoadOneById(tx, apiSessionCert.ApiSessionId) + apiSession, err = broker.ae.GetStores().ApiSession.LoadById(tx, apiSessionCert.ApiSessionId) return err }) diff --git a/controller/internal/policy/service_policy_enforcer.go b/controller/internal/policy/service_policy_enforcer.go index 9b0189b35..0a624f016 100644 --- a/controller/internal/policy/service_policy_enforcer.go +++ b/controller/internal/policy/service_policy_enforcer.go @@ -78,7 +78,7 @@ func (enforcer *ServicePolicyEnforcer) handleServiceEvent(event *db.ServiceEvent var sessionsToDelete []string err := enforcer.appEnv.GetDbProvider().GetDb().View(func(tx *bbolt.Tx) error { - identity, err := enforcer.appEnv.GetStores().Identity.LoadOneById(tx, event.IdentityId) + identity, err := enforcer.appEnv.GetStores().Identity.LoadById(tx, event.IdentityId) if err != nil { return err } @@ -134,12 +134,12 @@ func (enforcer *ServicePolicyEnforcer) Run() error { var sessionsToRemove []string err = enforcer.appEnv.GetDbProvider().GetDb().View(func(tx *bbolt.Tx) error { for _, session := range result.Sessions { - apiSession, err := enforcer.appEnv.GetStores().ApiSession.LoadOneById(tx, session.ApiSessionId) + apiSession, err := enforcer.appEnv.GetStores().ApiSession.LoadById(tx, session.ApiSessionId) if err != nil { return err } - identity, err := enforcer.appEnv.GetStores().Identity.LoadOneById(tx, apiSession.IdentityId) + identity, err := enforcer.appEnv.GetStores().Identity.LoadById(tx, apiSession.IdentityId) if err != nil { return err } diff --git a/controller/model/api_session_certificate_model.go b/controller/model/api_session_certificate_model.go index 6f2d32553..51cb0854e 100644 --- a/controller/model/api_session_certificate_model.go +++ b/controller/model/api_session_certificate_model.go @@ -86,7 +86,7 @@ func (entity *ApiSessionCertificate) fillFrom(env Env, tx *bbolt.Tx, boltApiSess entity.PEM = boltApiSessionCertificate.PEM entity.ApiSessionId = boltApiSessionCertificate.ApiSessionId - boltApiSession, err := env.GetStores().ApiSession.LoadOneById(tx, boltApiSessionCertificate.ApiSessionId) + boltApiSession, err := env.GetStores().ApiSession.LoadById(tx, boltApiSessionCertificate.ApiSessionId) if err != nil { return err } diff --git a/controller/model/api_session_model.go b/controller/model/api_session_model.go index 039c8a463..329dfa6e0 100644 --- a/controller/model/api_session_model.go +++ b/controller/model/api_session_model.go @@ -82,7 +82,7 @@ func (entity *ApiSession) fillFrom(env Env, tx *bbolt.Tx, boltApiSession *db.Api entity.LastActivityAt = boltApiSession.LastActivityAt entity.AuthenticatorId = boltApiSession.AuthenticatorId - boltIdentity, err := env.GetStores().Identity.LoadOneById(tx, boltApiSession.IdentityId) + boltIdentity, err := env.GetStores().Identity.LoadById(tx, boltApiSession.IdentityId) if err != nil { return err } diff --git a/controller/model/authenticator_manager.go b/controller/model/authenticator_manager.go index 55cc6030b..5cefa3d66 100644 --- a/controller/model/authenticator_manager.go +++ b/controller/model/authenticator_manager.go @@ -87,7 +87,7 @@ func (self *AuthenticatorManager) ReadFingerprints(authenticatorId string) ([]st err := self.env.GetDbProvider().GetDb().View(func(tx *bbolt.Tx) error { var err error - authenticator, err = self.authStore.LoadOneById(tx, authenticatorId) + authenticator, err = self.authStore.LoadById(tx, authenticatorId) return err }) @@ -677,7 +677,7 @@ func getCaId(env Env, auth *AuthenticatorCert) string { caId := "" err := env.GetDbProvider().GetDb().View(func(tx *bbolt.Tx) error { for cursor := env.GetStores().Ca.IterateIds(tx, ast.BoolNodeTrue); cursor.IsValid(); cursor.Next() { - ca, err := env.GetStores().Ca.LoadOneById(tx, string(cursor.Current())) + ca, err := env.GetStores().Ca.LoadById(tx, string(cursor.Current())) if err != nil { continue } diff --git a/controller/model/authenticator_mod_ext_jwt.go b/controller/model/authenticator_mod_ext_jwt.go index 591ccb795..d969c242d 100644 --- a/controller/model/authenticator_mod_ext_jwt.go +++ b/controller/model/authenticator_mod_ext_jwt.go @@ -566,7 +566,7 @@ func (a *AuthModuleExtJwt) loadExistingSigners() { } for _, id := range ids { - signer, err := a.env.GetStores().ExternalJwtSigner.LoadOneById(tx, id) + signer, err := a.env.GetStores().ExternalJwtSigner.LoadById(tx, id) if err != nil { return err } diff --git a/controller/model/create_terminator_cmd.go b/controller/model/create_terminator_cmd.go index 5cb1955d1..cb6415def 100644 --- a/controller/model/create_terminator_cmd.go +++ b/controller/model/create_terminator_cmd.go @@ -93,7 +93,7 @@ func (self *CreateEdgeTerminatorCmd) getTerminatorSession(tx *bbolt.Tx, terminat } if session.ApiSession == nil { - apiSession, err := self.Env.GetStores().ApiSession.LoadOneById(tx, session.ApiSessionId) + apiSession, err := self.Env.GetStores().ApiSession.LoadById(tx, session.ApiSessionId) if err != nil { return nil, err } diff --git a/controller/model/edge_service_manager.go b/controller/model/edge_service_manager.go index 5918b45c3..e42e082f7 100644 --- a/controller/model/edge_service_manager.go +++ b/controller/model/edge_service_manager.go @@ -287,7 +287,7 @@ func (self *EdgeServiceManager) mergeConfigs(tx *bbolt.Tx, configTypes map[strin if len(configTypes) > 0 && len(service.Configs) > 0 { configStore := self.env.GetStores().Config for _, configId := range service.Configs { - config, _ := configStore.LoadOneById(tx, configId) + config, _ := configStore.LoadById(tx, configId) if config != nil { _, wantsConfig := configTypes[config.Type] if wantsAll || wantsConfig { diff --git a/controller/model/edge_service_model.go b/controller/model/edge_service_model.go index 75a6d6daa..b3e411689 100644 --- a/controller/model/edge_service_model.go +++ b/controller/model/edge_service_model.go @@ -63,14 +63,14 @@ func (entity *Service) validateConfigs(tx *bbolt.Tx, env Env) error { typeMap := map[string]*db.Config{} configStore := env.GetStores().Config for _, id := range entity.Configs { - config, _ := configStore.LoadOneById(tx, id) + config, _ := configStore.LoadById(tx, id) if config == nil { return boltz.NewNotFoundError(db.EntityTypeConfigs, "id", id) } conflictConfig, found := typeMap[config.Type] if found { configTypeName := "" - if configType, _ := env.GetStores().ConfigType.LoadOneById(tx, config.Type); configType != nil { + if configType, _ := env.GetStores().ConfigType.LoadById(tx, config.Type); configType != nil { configTypeName = configType.Name } msg := fmt.Sprintf("duplicate configs named %v and %v found for config type %v. Only one config of a given typed is allowed per service ", diff --git a/controller/model/mfa_model.go b/controller/model/mfa_model.go index 93d8cd372..6b0d7685a 100644 --- a/controller/model/mfa_model.go +++ b/controller/model/mfa_model.go @@ -68,7 +68,7 @@ func (entity *Mfa) fillFrom(env Env, tx *bbolt.Tx, boltMfa *db.Mfa) error { entity.IdentityId = boltMfa.IdentityId entity.RecoveryCodes = boltMfa.RecoveryCodes entity.Secret = boltMfa.Secret - boltIdentity, err := env.GetStores().Identity.LoadOneById(tx, boltMfa.IdentityId) + boltIdentity, err := env.GetStores().Identity.LoadById(tx, boltMfa.IdentityId) if err != nil { return err } diff --git a/controller/model/policy_advisor.go b/controller/model/policy_advisor.go index a41a3e6cc..456790639 100644 --- a/controller/model/policy_advisor.go +++ b/controller/model/policy_advisor.go @@ -82,7 +82,7 @@ func (advisor *PolicyAdvisor) getServicePermissions(identityId, serviceId string servicePolicyStore := advisor.env.GetStores().ServicePolicy servicePolicyIterator := func(tx *bbolt.Tx, servicePolicyId string) error { - servicePolicy, err := servicePolicyStore.LoadOneById(tx, servicePolicyId) + servicePolicy, err := servicePolicyStore.LoadById(tx, servicePolicyId) if err != nil { return err } diff --git a/controller/model/posture_response_manager.go b/controller/model/posture_response_manager.go index d6353948b..ddfcf8c02 100644 --- a/controller/model/posture_response_manager.go +++ b/controller/model/posture_response_manager.go @@ -289,7 +289,7 @@ func (self *PostureResponseManager) GetEndpointStateChangeAffectedServices(timeS cursor := self.env.GetStores().PostureCheck.IterateIds(tx, query) for cursor.IsValid() { - if check, err := self.env.GetStores().PostureCheck.LoadOneById(tx, string(cursor.Current())); err == nil { + if check, err := self.env.GetStores().PostureCheck.LoadById(tx, string(cursor.Current())); err == nil { if mfaCheck, ok := check.SubType.(*db.PostureCheckMfa); ok { if shouldPostureCheckTimeoutBeAltered(mfaCheck, timeSinceLastMfa, gracePeriod, onWake, onUnlock) { affectedChecks[check.Id] = mfaCheck.TimeoutSeconds @@ -321,7 +321,7 @@ func (self *PostureResponseManager) GetEndpointStateChangeAffectedServices(timeS for serviceCursor.IsValid() { if _, ok := services[string(serviceCursor.Current())]; !ok { - service, err := self.env.GetStores().EdgeService.LoadOneById(tx, string(serviceCursor.Current())) + service, err := self.env.GetStores().EdgeService.LoadById(tx, string(serviceCursor.Current())) if err == nil { modelService := &Service{} if err := modelService.fillFrom(self.env, tx, service); err == nil { diff --git a/controller/model/posture_response_model.go b/controller/model/posture_response_model.go index 4897d0382..97bc533d2 100644 --- a/controller/model/posture_response_model.go +++ b/controller/model/posture_response_model.go @@ -122,7 +122,7 @@ func (pc *PostureCache) evaluate() { } for cursor.IsValid() && len(sessions) < maxScanPerTx { - if session, _ := pc.env.GetStores().Session.LoadOneById(tx, string(cursor.Current())); session != nil { + if session, _ := pc.env.GetStores().Session.LoadById(tx, string(cursor.Current())); session != nil { sessions = append(sessions, session) } lastId = cursor.Current() diff --git a/controller/model/session_model.go b/controller/model/session_model.go index 64518dc91..b32d86931 100644 --- a/controller/model/session_model.go +++ b/controller/model/session_model.go @@ -35,7 +35,7 @@ type Session struct { } func (entity *Session) toBoltEntityForCreate(tx *bbolt.Tx, env Env) (*db.Session, error) { - apiSession, err := env.GetStores().ApiSession.LoadOneById(tx, entity.ApiSessionId) + apiSession, err := env.GetStores().ApiSession.LoadById(tx, entity.ApiSessionId) if err != nil { return nil, err } diff --git a/controller/sync_strats/sync_instant.go b/controller/sync_strats/sync_instant.go index ca27cef83..e8a426a76 100644 --- a/controller/sync_strats/sync_instant.go +++ b/controller/sync_strats/sync_instant.go @@ -619,7 +619,7 @@ func (strategy *InstantStrategy) synchronize(rtx *RouterSender) { for cursor := strategy.ae.GetStores().ApiSession.IterateIds(tx, ast.BoolNodeTrue); cursor.IsValid(); cursor.Next() { current := cursor.Current() - apiSession, err := strategy.ae.GetStores().ApiSession.LoadOneById(tx, string(current)) + apiSession, err := strategy.ae.GetStores().ApiSession.LoadById(tx, string(current)) if err != nil { logger.WithError(err).WithField("apiSessionId", string(current)).Errorf("error querying api session [%s]: %v", string(current), err) @@ -782,7 +782,7 @@ func (strategy *InstantStrategy) BuildServicePolicies(tx *bbolt.Tx) error { currentBytes := cursor.Current() currentId := string(currentBytes) - storeModel, err := strategy.ae.GetStores().ServicePolicy.LoadOneById(tx, currentId) + storeModel, err := strategy.ae.GetStores().ServicePolicy.LoadById(tx, currentId) if err != nil { return err @@ -831,7 +831,7 @@ func (strategy *InstantStrategy) BuildPublicKeys(tx *bbolt.Tx) error { currentBytes := cursor.Current() currentId := string(currentBytes) - ca, err := strategy.ae.GetStores().Ca.LoadOneById(tx, currentId) + ca, err := strategy.ae.GetStores().Ca.LoadById(tx, currentId) if err != nil { return err @@ -953,7 +953,7 @@ func (strategy *InstantStrategy) BuildPostureChecks(tx *bbolt.Tx) error { } func newIdentityById(tx *bbolt.Tx, ae *env.AppEnv, id string) (*edge_ctrl_pb.DataState_Identity, error) { - identityModel, err := ae.GetStores().Identity.LoadOneById(tx, id) + identityModel, err := ae.GetStores().Identity.LoadById(tx, id) if err != nil { return nil, err @@ -985,7 +985,7 @@ func newServicePolicy(tx *bbolt.Tx, env *env.AppEnv, storeModel *db.ServicePolic } func newServiceById(tx *bbolt.Tx, ae *env.AppEnv, id string) (*edge_ctrl_pb.DataState_Service, error) { - storeModel, err := ae.GetStores().EdgeService.LoadOneById(tx, id) + storeModel, err := ae.GetStores().EdgeService.LoadById(tx, id) if err != nil { return nil, err @@ -1011,7 +1011,7 @@ func newPublicKey(data []byte, format edge_ctrl_pb.DataState_PublicKey_Format, u } func newPostureCheckById(tx *bbolt.Tx, ae *env.AppEnv, id string) (*edge_ctrl_pb.DataState_PostureCheck, error) { - postureModel, err := ae.GetStores().PostureCheck.LoadOneById(tx, id) + postureModel, err := ae.GetStores().PostureCheck.LoadById(tx, id) if err != nil { return nil, err diff --git a/ziti/cmd/database/add_debug_admin.go b/ziti/cmd/database/add_debug_admin.go index 020946241..d69fdc587 100644 --- a/ziti/cmd/database/add_debug_admin.go +++ b/ziti/cmd/database/add_debug_admin.go @@ -91,7 +91,7 @@ func (action *addDebugAdminAction) run(dbFile, username, password string) { ctx := change.New().SetChangeAuthorType("cli.debug-db").NewMutateContext() err = dbProvider.GetDb().Update(ctx, func(ctx boltz.MutateContext) error { tx := ctx.Tx() - identity, _ := stores.Identity.LoadOneById(tx, id) + identity, _ := stores.Identity.LoadById(tx, id) if identity != nil { if err = stores.Identity.DeleteById(ctx, id); err != nil { return err diff --git a/zititest/zitilab/models/db_builder.go b/zititest/zitilab/models/db_builder.go index f6938e6e9..e02efab21 100644 --- a/zititest/zitilab/models/db_builder.go +++ b/zititest/zitilab/models/db_builder.go @@ -70,7 +70,7 @@ func (self *ZitiDbBuilder) CreateEdgeRouterHosts(tx *bbolt.Tx, m *model.Model) e } for _, id := range ids { - er, err := self.stores.EdgeRouter.LoadOneById(tx, id) + er, err := self.stores.EdgeRouter.LoadById(tx, id) if err != nil { return err }