diff --git a/controller/persistence/appwan_store.go b/controller/persistence/appwan_store.go deleted file mode 100644 index f2b3f6236..000000000 --- a/controller/persistence/appwan_store.go +++ /dev/null @@ -1,89 +0,0 @@ -/* - Copyright NetFoundry, Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - https://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -package persistence - -import ( - "errors" - "github.com/openziti/foundation/storage/boltz" - "go.etcd.io/bbolt" -) - -type Appwan struct { - boltz.BaseExtEntity - Name string - Identities []string - Services []string -} - -func (entity *Appwan) LoadValues(_ boltz.CrudStore, bucket *boltz.TypedBucket) { - entity.LoadBaseValues(bucket) - entity.Name = bucket.GetStringOrError(FieldName) - entity.Identities = bucket.GetStringList(EntityTypeIdentities) - entity.Services = bucket.GetStringList(EntityTypeServices) -} - -func (entity *Appwan) SetValues(ctx *boltz.PersistContext) { - ctx.Bucket.SetError(errors.New("the appwan entity type is deprecated. it may be read, but not written")) -} - -func (entity *Appwan) GetEntityType() string { - return EntityTypeAppwans -} - -type AppwanStore interface { - Store - LoadOneById(tx *bbolt.Tx, id string) (*Appwan, error) -} - -func newAppwanStore(stores *stores) *appwanStoreImpl { - store := &appwanStoreImpl{ - baseStore: newBaseStore(stores, EntityTypeAppwans), - } - store.InitImpl(store) - return store -} - -type appwanStoreImpl struct { - *baseStore - - indexName boltz.ReadIndex - symbolIdentities boltz.EntitySetSymbol - symbolServices boltz.EntitySetSymbol -} - -func (store *appwanStoreImpl) NewStoreEntity() boltz.Entity { - return &Appwan{} -} - -func (store *appwanStoreImpl) initializeLocal() { - store.AddExtEntitySymbols() - - store.indexName = store.addUniqueNameField() - store.symbolServices = store.AddFkSetSymbol(EntityTypeServices, store.stores.edgeService) - store.symbolIdentities = store.AddFkSetSymbol(EntityTypeIdentities, store.stores.identity) -} - -func (store *appwanStoreImpl) initializeLinked() { -} - -func (store *appwanStoreImpl) LoadOneById(tx *bbolt.Tx, id string) (*Appwan, error) { - entity := &Appwan{} - if err := store.baseLoadOneById(tx, id, entity); err != nil { - return nil, err - } - return entity, nil -} diff --git a/controller/persistence/base_store.go b/controller/persistence/base_store.go index f4b16e126..d7a0df0e8 100644 --- a/controller/persistence/base_store.go +++ b/controller/persistence/base_store.go @@ -48,24 +48,23 @@ func newBaseStore(stores *stores, entityType string) *baseStore { singularEntityType := boltz.GetSingularEntityType(entityType) return &baseStore{ stores: stores, - BaseStore: boltz.NewBaseStore(nil, entityType, func(id string) error { + BaseStore: boltz.NewBaseStore(entityType, func(id string) error { return boltz.NewNotFoundError(singularEntityType, "id", id) }, boltz.RootBucket), } } -func newChildBaseStore(stores *stores, parent boltz.CrudStore, entityType string) *baseStore { - singularEntityType := boltz.GetSingularEntityType(entityType) +func newChildBaseStore(stores *stores, parent boltz.CrudStore) *baseStore { return &baseStore{ stores: stores, - BaseStore: boltz.NewBaseStore(parent, entityType, func(id string) error { - return boltz.NewNotFoundError(singularEntityType, "id", id) + BaseStore: boltz.NewChildBaseStore(parent, func(id string) error { + return boltz.NewNotFoundError(parent.GetSingularEntityType(), "id", id) }, EdgeBucket), } } -func newExtendedBaseStore(stores *stores, parent boltz.CrudStore, entityType string) *baseStore { - store := newChildBaseStore(stores, parent, entityType) +func newExtendedBaseStore(stores *stores, parent boltz.CrudStore) *baseStore { + store := newChildBaseStore(stores, parent) store.BaseStore.Extended() return store } diff --git a/controller/persistence/cluster_store.go b/controller/persistence/cluster_store.go deleted file mode 100644 index d087a5cac..000000000 --- a/controller/persistence/cluster_store.go +++ /dev/null @@ -1,108 +0,0 @@ -/* - Copyright NetFoundry, Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - https://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -package persistence - -import ( - "github.com/openziti/foundation/storage/boltz" - "github.com/pkg/errors" - "go.etcd.io/bbolt" -) - -type Cluster struct { - boltz.BaseExtEntity - Name string -} - -func (entity *Cluster) LoadValues(_ boltz.CrudStore, bucket *boltz.TypedBucket) { - entity.LoadBaseValues(bucket) - entity.Name = bucket.GetStringOrError(FieldName) -} - -func (entity *Cluster) SetValues(ctx *boltz.PersistContext) { - entity.SetBaseValues(ctx) - ctx.SetString(FieldName, entity.Name) - // EdgeRouters are managed from edgeRouter - // Services are managed from services -} - -func (entity *Cluster) GetEntityType() string { - return EntityTypeClusters -} - -type ClusterStore interface { - Store - LoadOneById(tx *bbolt.Tx, id string) (*Cluster, error) - GetNameIndex() boltz.ReadIndex -} - -func newClusterStore(stores *stores) *clusterStoreImpl { - store := &clusterStoreImpl{ - baseStore: newBaseStore(stores, EntityTypeClusters), - } - store.InitImpl(store) - return store -} - -type clusterStoreImpl struct { - *baseStore - - indexName boltz.ReadIndex - symbolEdgeRouters boltz.EntitySetSymbol - symbolServices boltz.EntitySetSymbol -} - -func (store *clusterStoreImpl) NewStoreEntity() boltz.Entity { - return &Cluster{} -} - -func (store *clusterStoreImpl) GetNameIndex() boltz.ReadIndex { - return store.indexName -} - -func (store *clusterStoreImpl) initializeLocal() { - store.AddExtEntitySymbols() - - store.indexName = store.addUniqueNameField() - store.symbolEdgeRouters = store.AddFkSetSymbol(EntityTypeEdgeRouters, store.stores.edgeRouter) - store.symbolServices = store.AddFkSetSymbol(EntityTypeServices, store.stores.edgeService) -} - -func (store *clusterStoreImpl) initializeLinked() { - store.AddLinkCollection(store.symbolServices, store.stores.edgeService.symbolClusters) -} - -func (store *clusterStoreImpl) LoadOneById(tx *bbolt.Tx, id string) (*Cluster, error) { - entity := &Cluster{} - if err := store.baseLoadOneById(tx, id, entity); err != nil { - return nil, err - } - return entity, nil -} - -func (store *clusterStoreImpl) DeleteById(ctx boltz.MutateContext, id string) error { - if bucket := store.GetEntityBucket(ctx.Tx(), []byte(id)); bucket != nil { - if !bucket.IsStringListEmpty(EntityTypeEdgeRouters) { - return errors.Errorf("cannot delete cluster %v, which has edge routers assigned to it", id) - } - - if !bucket.IsStringListEmpty(EntityTypeServices) { - return errors.Errorf("cannot delete cluster %v, which has services assigned to it", id) - } - } - - return store.baseStore.DeleteById(ctx, id) -} diff --git a/controller/persistence/edge_router_store.go b/controller/persistence/edge_router_store.go index 865a70d45..c8b2d5b24 100644 --- a/controller/persistence/edge_router_store.go +++ b/controller/persistence/edge_router_store.go @@ -29,7 +29,6 @@ import ( const ( FieldEdgeRouterFingerprint = "fingerprint" FieldEdgeRouterCertPEM = "certPem" - FieldEdgeRouterCluster = "cluster" FieldEdgeRouterIsVerified = "isVerified" FieldEdgeRouterHostname = "hostname" FieldEdgeRouterProtocols = "protocols" @@ -49,7 +48,6 @@ func newEdgeRouter(name string, roleAttributes ...string) *EdgeRouter { type EdgeRouter struct { boltz.BaseExtEntity Name string - ClusterId *string IsVerified bool Fingerprint *string CertPem *string @@ -65,14 +63,11 @@ type EdgeRouter struct { EnrollmentExpiresAt *time.Time } -var edgeRouterFieldMappings = map[string]string{FieldEdgeRouterCluster: "clusterId"} - func (entity *EdgeRouter) LoadValues(_ boltz.CrudStore, bucket *boltz.TypedBucket) { entity.LoadBaseValues(bucket) entity.Name = bucket.GetStringOrError(FieldName) entity.Fingerprint = bucket.GetString(FieldEdgeRouterFingerprint) entity.CertPem = bucket.GetString(FieldEdgeRouterCertPEM) - entity.ClusterId = bucket.GetString(FieldEdgeRouterCluster) entity.IsVerified = bucket.GetBoolWithDefault(FieldEdgeRouterIsVerified, false) //old v4, migrations only @@ -83,8 +78,6 @@ func (entity *EdgeRouter) LoadValues(_ boltz.CrudStore, bucket *boltz.TypedBucke } func (entity *EdgeRouter) SetValues(ctx *boltz.PersistContext) { - ctx.WithFieldOverrides(edgeRouterFieldMappings) - entity.SetBaseValues(ctx) store := ctx.Store.(*edgeRouterStoreImpl) ctx.SetString(FieldName, entity.Name) diff --git a/controller/persistence/edge_service_store.go b/controller/persistence/edge_service_store.go index bb37794ee..2e2021123 100644 --- a/controller/persistence/edge_service_store.go +++ b/controller/persistence/edge_service_store.go @@ -34,10 +34,6 @@ type EdgeService struct { Configs []string } -const ( - FieldServiceClusters = "clusters" -) - func newEdgeService(name string, roleAttributes ...string) *EdgeService { return &EdgeService{ Service: db.Service{ @@ -64,7 +60,6 @@ func (entity *EdgeService) SetValues(ctx *boltz.PersistContext) { entity.SetBaseValues(ctx) store := ctx.Store.(*edgeServiceStoreImpl) ctx.SetString(FieldName, entity.Name) - ctx.SetString(FieldName, entity.Name) ctx.SetStringList(FieldRoleAttributes, entity.RoleAttributes) ctx.SetLinkedIds(EntityTypeConfigs, entity.Configs) @@ -94,7 +89,7 @@ type EdgeServiceStore interface { func newEdgeServiceStore(stores *stores) *edgeServiceStoreImpl { store := &edgeServiceStoreImpl{ - baseStore: newChildBaseStore(stores, stores.Service, EntityTypeServices), + baseStore: newChildBaseStore(stores, stores.Service), } store.InitImpl(store) return store @@ -128,7 +123,6 @@ func (store *edgeServiceStoreImpl) initializeLocal() { store.indexName = store.addUniqueNameField() store.indexRoleAttributes = store.addRoleAttributesField() - store.symbolClusters = store.AddFkSetSymbol(FieldServiceClusters, store.stores.cluster) store.symbolSessions = store.AddFkSetSymbol(EntityTypeSessions, store.stores.session) store.symbolServiceEdgeRouterPolicies = store.AddFkSetSymbol(EntityTypeServiceEdgeRouterPolicies, store.stores.serviceEdgeRouterPolicy) store.symbolServicePolicies = store.AddFkSetSymbol(EntityTypeServicePolicies, store.stores.servicePolicy) @@ -152,7 +146,6 @@ func (store *edgeServiceStoreImpl) rolesChanged(tx *bbolt.Tx, rowId []byte, _ [] } func (store *edgeServiceStoreImpl) initializeLinked() { - store.AddLinkCollection(store.symbolClusters, store.stores.cluster.symbolServices) store.AddLinkCollection(store.symbolServiceEdgeRouterPolicies, store.stores.serviceEdgeRouterPolicy.symbolServices) store.AddLinkCollection(store.symbolServicePolicies, store.stores.servicePolicy.symbolServices) store.AddLinkCollection(store.symbolConfigs, store.stores.config.symbolServices) diff --git a/controller/persistence/event_log_store.go b/controller/persistence/event_log_store.go index 489322dd5..18f1267c3 100644 --- a/controller/persistence/event_log_store.go +++ b/controller/persistence/event_log_store.go @@ -96,7 +96,7 @@ type eventLogStoreImpl struct { } func (store *eventLogStoreImpl) NewStoreEntity() boltz.Entity { - return &Cluster{} + return &EventLog{} } func (store *eventLogStoreImpl) initializeLocal() { diff --git a/controller/persistence/migration_v1.go b/controller/persistence/migration_initialize.go similarity index 55% rename from controller/persistence/migration_v1.go rename to controller/persistence/migration_initialize.go index c3d3d8f2c..216dabd22 100644 --- a/controller/persistence/migration_v1.go +++ b/controller/persistence/migration_initialize.go @@ -16,7 +16,10 @@ package persistence -import "github.com/openziti/foundation/storage/boltz" +import ( + "github.com/openziti/foundation/storage/boltz" + "math" +) func (m *Migrations) initialize(step *boltz.MigrationStep) int { versionBucket := boltz.GetOrCreatePath(step.Ctx.Tx(), boltz.RootBucket) @@ -30,8 +33,9 @@ func (m *Migrations) initialize(step *boltz.MigrationStep) int { m.createGeoRegionsV1(step) m.createIdentityTypesV1(step) + m.createInitialTunnelerConfigTypes(step) - return 1 + return CurrentDbVersion } var geoRegionsV1 = map[string]string{ @@ -77,3 +81,69 @@ func (m *Migrations) createIdentityTypesV1(step *boltz.MigrationStep) { })) } } + +var clientConfigV1TypeId = "f2dd2df0-9c04-4b84-a91e-71437ac229f1" +var serverConfigV1TypeId = "cea49285-6c07-42cf-9f52-09a9b115c783" + +func (m *Migrations) createInitialTunnelerConfigTypes(step *boltz.MigrationStep) { + clientConfigTypeV1 := &ConfigType{ + BaseExtEntity: boltz.BaseExtEntity{Id: clientConfigV1TypeId}, + Name: "ziti-tunneler-client.v1", + Schema: map[string]interface{}{ + "$id": "http://edge.openziti.org/schemas/ziti-tunneler-client.v1.config.json", + "type": "object", + "additionalProperties": false, + "required": []interface{}{ + "hostname", + "port", + }, + "properties": map[string]interface{}{ + // TODO: Add protocol list here, so we know which protocols to listen on + "hostname": map[string]interface{}{ + "type": "string", + }, + "port": map[string]interface{}{ + "type": "integer", + "minimum": float64(0), + "maximum": float64(math.MaxUint16), + }, + }, + }, + } + step.SetError(m.stores.ConfigType.Create(step.Ctx, clientConfigTypeV1)) + + serverConfigTypeV1 := &ConfigType{ + BaseExtEntity: boltz.BaseExtEntity{Id: serverConfigV1TypeId}, + Name: "ziti-tunneler-server.v1", + Schema: map[string]interface{}{ + "$id": "http://edge.openziti.org/schemas/ziti-tunneler-server.v1.config.json", + "type": "object", + "additionalProperties": false, + "required": []interface{}{ + "hostname", + "port", + }, + "properties": map[string]interface{}{ + "protocol": map[string]interface{}{ + "type": []interface{}{ + "string", + "null", + }, + "enum": []interface{}{ + "tcp", + "udp", + }, + }, + "hostname": map[string]interface{}{ + "type": "string", + }, + "port": map[string]interface{}{ + "type": "integer", + "minimum": float64(0), + "maximum": float64(math.MaxUint16), + }, + }, + }, + } + step.SetError(m.stores.ConfigType.Create(step.Ctx, serverConfigTypeV1)) +} diff --git a/controller/persistence/migration_v2.go b/controller/persistence/migration_v2.go deleted file mode 100644 index 280fe3a1f..000000000 --- a/controller/persistence/migration_v2.go +++ /dev/null @@ -1,79 +0,0 @@ -/* - Copyright NetFoundry, Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - https://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -package persistence - -import ( - "github.com/google/uuid" - "github.com/openziti/foundation/storage/boltz" -) - -func (m *Migrations) createEdgeRouterPoliciesV2(step *boltz.MigrationStep) { - _, serviceCount, err := m.stores.EdgeService.QueryIds(step.Ctx.Tx(), "true") - step.SetError(err) - - _, routerCount, err := m.stores.EdgeRouter.QueryIds(step.Ctx.Tx(), "true") - - // Only continue if there are services that might stop working if we don't create default or migrated policies - if step.SetError(err) || serviceCount == 0 || routerCount == 0 { - return - } - - allPolicy := &EdgeRouterPolicy{ - BaseExtEntity: boltz.BaseExtEntity{Id: uuid.New().String()}, - Name: "migration policy allowing access to all edge routers and all identities", - IdentityRoles: []string{AllRole}, - EdgeRouterRoles: []string{AllRole}, - } - step.SetError(m.stores.EdgeRouterPolicy.Create(step.Ctx, allPolicy)) - - edgeRouterIds, _, err := m.stores.EdgeRouter.QueryIds(step.Ctx.Tx(), "true") - step.SetError(err) - - for _, edgeRouterId := range edgeRouterIds { - edgeRouter, err := m.stores.EdgeRouter.LoadOneById(step.Ctx.Tx(), edgeRouterId) - if step.SetError(err) { - return - } - if edgeRouter.ClusterId == nil { - continue - } - cluster, err := m.stores.Cluster.LoadOneById(step.Ctx.Tx(), *edgeRouter.ClusterId) - step.SetError(err) - edgeRouter.RoleAttributes = append(edgeRouter.RoleAttributes, "cluster-"+cluster.Name) - step.SetError(m.stores.EdgeRouter.Update(step.Ctx, edgeRouter, nil)) - } - - clusterIds, _, err := m.stores.Cluster.QueryIds(step.Ctx.Tx(), "true") - step.SetError(err) - for _, clusterId := range clusterIds { - name := string(m.stores.Cluster.GetNameIndex().Read(step.Ctx.Tx(), []byte(clusterId))) - serviceIds := m.stores.Cluster.GetRelatedEntitiesIdList(step.Ctx.Tx(), clusterId, EntityTypeServices) - edgeRouterIds := m.stores.Cluster.GetRelatedEntitiesIdList(step.Ctx.Tx(), clusterId, EntityTypeEdgeRouters) - - serviceEdgeRouterPolicy := newServiceEdgeRouterPolicy(name) - for _, serviceId := range serviceIds { - serviceEdgeRouterPolicy.ServiceRoles = append(serviceEdgeRouterPolicy.ServiceRoles, "@"+serviceId) - } - - for _, edgeRouterId := range edgeRouterIds { - serviceEdgeRouterPolicy.EdgeRouterRoles = append(serviceEdgeRouterPolicy.ServiceRoles, "@"+edgeRouterId) - } - if step.SetError(m.stores.ServiceEdgeRouterPolicy.Create(step.Ctx, serviceEdgeRouterPolicy)) { - return - } - } -} diff --git a/controller/persistence/migration_v3.go b/controller/persistence/migration_v3.go deleted file mode 100644 index 71b530888..000000000 --- a/controller/persistence/migration_v3.go +++ /dev/null @@ -1,48 +0,0 @@ -/* - Copyright NetFoundry, Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - https://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -package persistence - -import "github.com/openziti/foundation/storage/boltz" - -func (m *Migrations) createServicePoliciesV3(step *boltz.MigrationStep) { - appwanIds, _, err := m.stores.Appwan.QueryIds(step.Ctx.Tx(), "true") - step.SetError(err) - for _, appwanId := range appwanIds { - appwan, err := m.stores.Appwan.LoadOneById(step.Ctx.Tx(), appwanId) - if step.SetError(err) { - return - } - - var identityRoles []string - for _, id := range appwan.Identities { - identityRoles = append(identityRoles, "@"+id) - } - - var serviceRoles []string - for _, id := range appwan.Services { - serviceRoles = append(serviceRoles, "@"+id) - } - - servicePolicy := &ServicePolicy{ - PolicyType: PolicyTypeDial, - Name: appwan.Name, - IdentityRoles: identityRoles, - ServiceRoles: serviceRoles, - } - step.SetError(m.stores.ServicePolicy.Create(step.Ctx, servicePolicy)) - } -} diff --git a/controller/persistence/migration_v4.go b/controller/persistence/migration_v4.go index 1532fe432..efc965202 100644 --- a/controller/persistence/migration_v4.go +++ b/controller/persistence/migration_v4.go @@ -20,7 +20,6 @@ import ( "github.com/google/uuid" "github.com/openziti/foundation/storage/ast" "github.com/openziti/foundation/storage/boltz" - "math" ) const ( @@ -28,72 +27,6 @@ const ( FieldServiceDnsPort = "dnsPort" ) -var clientConfigV1TypeId = "f2dd2df0-9c04-4b84-a91e-71437ac229f1" -var serverConfigV1TypeId = "cea49285-6c07-42cf-9f52-09a9b115c783" - -func (m *Migrations) createInitialTunnelerConfigTypes(step *boltz.MigrationStep) { - clientConfigTypeV1 := &ConfigType{ - BaseExtEntity: boltz.BaseExtEntity{Id: clientConfigV1TypeId}, - Name: "ziti-tunneler-client.v1", - Schema: map[string]interface{}{ - "$id": "http://ziti-edge.netfoundry.io/schemas/ziti-tunneler-client.v1.config.json", - "type": "object", - "additionalProperties": false, - "required": []interface{}{ - "hostname", - "port", - }, - "properties": map[string]interface{}{ - // TODO: Add protocol list here, so we know which protocols to listen on - "hostname": map[string]interface{}{ - "type": "string", - }, - "port": map[string]interface{}{ - "type": "integer", - "minimum": float64(0), - "maximum": float64(math.MaxUint16), - }, - }, - }, - } - step.SetError(m.stores.ConfigType.Create(step.Ctx, clientConfigTypeV1)) - - serverConfigTypeV1 := &ConfigType{ - BaseExtEntity: boltz.BaseExtEntity{Id: serverConfigV1TypeId}, - Name: "ziti-tunneler-server.v1", - Schema: map[string]interface{}{ - "$id": "http://ziti-edge.netfoundry.io/schemas/ziti-tunneler-server.v1.config.json", - "type": "object", - "additionalProperties": false, - "required": []interface{}{ - "hostname", - "port", - }, - "properties": map[string]interface{}{ - "protocol": map[string]interface{}{ - "type": []interface{}{ - "string", - "null", - }, - "enum": []interface{}{ - "tcp", - "udp", - }, - }, - "hostname": map[string]interface{}{ - "type": "string", - }, - "port": map[string]interface{}{ - "type": "integer", - "minimum": float64(0), - "maximum": float64(math.MaxUint16), - }, - }, - }, - } - step.SetError(m.stores.ConfigType.Create(step.Ctx, serverConfigTypeV1)) -} - func (m *Migrations) createInitialTunnelerConfigs(step *boltz.MigrationStep) { ids, _, err := m.stores.EdgeService.QueryIds(step.Ctx.Tx(), "true") step.SetError(err) diff --git a/controller/persistence/migrations.go b/controller/persistence/migrations.go index 4b8429fdd..27a6f157a 100644 --- a/controller/persistence/migrations.go +++ b/controller/persistence/migrations.go @@ -44,35 +44,35 @@ func (m *Migrations) migrate(step *boltz.MigrationStep) int { return m.initialize(step) } - if step.CurrentVersion == 1 { - m.createEdgeRouterPoliciesV2(step) - return 2 + if step.CurrentVersion > CurrentDbVersion { + step.SetError(errors.Errorf("Unsupported edge datastore version: %v", step.CurrentVersion)) + return step.CurrentVersion } - if step.CurrentVersion == 2 { - m.createServicePoliciesV3(step) - return 3 - } + //if step.CurrentVersion < 2 { + // m.createEdgeRouterPoliciesV2(step) + //} + // + //if step.CurrentVersion < 3 { + // m.createServicePoliciesV3(step) + //} - if step.CurrentVersion == 3 { + if step.CurrentVersion < 4 { m.createInitialTunnelerConfigTypes(step) m.createInitialTunnelerConfigs(step) - return 4 } - if step.CurrentVersion == 4 { + if step.CurrentVersion < 5 { m.createEnrollmentsForEdgeRouters(step) - return 5 } - if step.CurrentVersion == 5 { + if step.CurrentVersion < 6 { m.fixIdentityBuckets(step) - return 6 } // current version - if step.CurrentVersion == 6 { - return 6 + if step.CurrentVersion <= CurrentDbVersion { + return CurrentDbVersion } step.SetError(errors.Errorf("Unsupported edge datastore version: %v", step.CurrentVersion)) diff --git a/controller/persistence/stores.go b/controller/persistence/stores.go index ae619ec72..ab58cff56 100644 --- a/controller/persistence/stores.go +++ b/controller/persistence/stores.go @@ -35,9 +35,7 @@ type Stores struct { Terminator db.TerminatorStore ApiSession ApiSessionStore - Appwan AppwanStore Ca CaStore - Cluster ClusterStore Config ConfigStore ConfigType ConfigTypeStore EdgeRouter EdgeRouterStore @@ -94,9 +92,7 @@ type stores struct { Terminator db.TerminatorStore apiSession *apiSessionStoreImpl - appwan *appwanStoreImpl ca *caStoreImpl - cluster *clusterStoreImpl config *configStoreImpl configType *configTypeStoreImpl edgeRouter *edgeRouterStoreImpl @@ -127,9 +123,7 @@ func NewBoltStores(dbProvider DbProvider) (*Stores, error) { internalStores.apiSession = newApiSessionStore(internalStores) internalStores.authenticator = newAuthenticatorStore(internalStores) - internalStores.appwan = newAppwanStore(internalStores) internalStores.ca = newCaStore(internalStores) - internalStores.cluster = newClusterStore(internalStores) internalStores.config = newConfigsStore(internalStores) internalStores.configType = newConfigTypesStore(internalStores) internalStores.edgeRouter = newEdgeRouterStore(internalStores) @@ -153,9 +147,7 @@ func NewBoltStores(dbProvider DbProvider) (*Stores, error) { Service: dbProvider.GetStores().Service, ApiSession: internalStores.apiSession, - Appwan: internalStores.appwan, Ca: internalStores.ca, - Cluster: internalStores.cluster, Config: internalStores.config, ConfigType: internalStores.configType, EdgeRouter: internalStores.edgeRouter, @@ -177,7 +169,7 @@ func NewBoltStores(dbProvider DbProvider) (*Stores, error) { // The Index store is used for querying indexes. It's a convenient store with only a single value (id), which // is only ever queried using an index set cursor - externalStores.Index = boltz.NewBaseStore(nil, "invalid", func(id string) error { + externalStores.Index = boltz.NewBaseStore("invalid", func(id string) error { return errors.Errorf("should never happen") }) externalStores.Index.AddIdSymbol("id", ast.NodeTypeString) diff --git a/controller/persistence/testing.go b/controller/persistence/testing.go index bb34f2654..90f48f745 100644 --- a/controller/persistence/testing.go +++ b/controller/persistence/testing.go @@ -120,7 +120,7 @@ func (ctx *TestContext) requireNewServicePolicy(policyType int32, identityRoles ctx.RequireCreate(entity) return entity } - + func (ctx *TestContext) requireNewIdentity(name string, isAdmin bool) *Identity { identity := &Identity{ BaseExtEntity: *boltz.NewExtEntity(uuid.New().String(), nil), @@ -172,12 +172,10 @@ func (ctx *TestContext) cleanupAll() { ctx.stores.Session, ctx.stores.ApiSession, ctx.stores.EdgeRouterPolicy, - ctx.stores.Appwan, ctx.stores.Service, ctx.stores.EdgeService, ctx.stores.Identity, ctx.stores.EdgeRouter, - ctx.stores.Cluster, ctx.stores.Config, } _ = ctx.GetDb().Update(func(tx *bbolt.Tx) error { diff --git a/controller/persistence/transit_router_store.go b/controller/persistence/transit_router_store.go index 3040b2b17..625075b08 100644 --- a/controller/persistence/transit_router_store.go +++ b/controller/persistence/transit_router_store.go @@ -27,12 +27,6 @@ import ( const ( FieldTransitRouterIsVerified = "isVerified" FieldTransitRouterEnrollments = "enrollments" - - //old - FieldTransitRouterEnrollmentToken = "enrollmentToken" - FieldTransitRouterEnrollmentJwt = "enrollmentJwt" - FieldTransitRouterEnrollmentCreatedAt = "enrollmentCreatedAt" - FieldTransitRouterEnrollmentExpiresAt = "enrollmentExpiresAt" ) type TransitRouter struct { @@ -86,7 +80,7 @@ func (entity *TransitRouter) SetValues(ctx *boltz.PersistContext) { } func (entity *TransitRouter) GetEntityType() string { - return EntityTypeTransitRouters + return db.EntityTypeRouters } func (entity *TransitRouter) GetName() string { @@ -101,7 +95,7 @@ type TransitRouterStore interface { func newTransitRouterStore(stores *stores) *transitRouterStoreImpl { store := &transitRouterStoreImpl{ - baseStore: newExtendedBaseStore(stores, stores.Router, EntityTypeTransitRouters), + baseStore: newExtendedBaseStore(stores, stores.Router), } store.InitImpl(store) return store diff --git a/go.mod b/go.mod index 96e0778f1..7cef0973f 100644 --- a/go.mod +++ b/go.mod @@ -35,7 +35,7 @@ require ( github.com/miekg/dns v1.1.29 github.com/mitchellh/mapstructure v1.3.0 github.com/oleiade/reflections v1.0.0 // indirect - github.com/openziti/fabric v0.11.39 + github.com/openziti/fabric v0.11.40 github.com/openziti/foundation v0.11.2 github.com/openziti/sdk-golang v0.13.3 github.com/pkg/errors v0.9.1 diff --git a/go.sum b/go.sum index 818015415..8ec9a4d97 100644 --- a/go.sum +++ b/go.sum @@ -286,8 +286,8 @@ github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= -github.com/openziti/fabric v0.11.39 h1:64QrGjoYHgAlVftE69GHbSE/DhOfpAuotJ47lX08qeQ= -github.com/openziti/fabric v0.11.39/go.mod h1:yoJHbU2nS969Ghfr1lEJguIFEzr9MrYixRmzN2ZZ/IA= +github.com/openziti/fabric v0.11.40 h1:IebmkMrAa7R216cBd1ROhON5RgiPFm9TVyqo7a2Aknk= +github.com/openziti/fabric v0.11.40/go.mod h1:LsIAeOvc0ygIPZ2QCuh2l/nWbt2pp2e431KAhNtixws= github.com/openziti/foundation v0.11.1 h1:hM6CefjMMPxD/iY/AFMmPRSIqLug6FqDUQJwvxQYwOk= github.com/openziti/foundation v0.11.1/go.mod h1:E+z3Ne+G1IrApCxg/+kKLFg5hUubElHyylvfCLJg4fk= github.com/openziti/foundation v0.11.2 h1:h6jsPLDkNzH1WTVPb8MPaECgYqEwzlXFwLRFeO1Aojk=