From a7be333879889662f0b13403b21489018d0b9d30 Mon Sep 17 00:00:00 2001 From: Andrew Martinez Date: Fri, 3 Sep 2021 09:48:21 -0400 Subject: [PATCH 1/3] adds migration to fill identityId for existing sessions --- controller/persistence/migration_v24.go | 56 +++++++++++++++++++++++++ controller/persistence/migrations.go | 6 ++- controller/persistence/session_store.go | 2 +- 3 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 controller/persistence/migration_v24.go diff --git a/controller/persistence/migration_v24.go b/controller/persistence/migration_v24.go new file mode 100644 index 000000000..fb8c4af4b --- /dev/null +++ b/controller/persistence/migration_v24.go @@ -0,0 +1,56 @@ +package persistence + +import ( + "fmt" + "github.com/openziti/foundation/storage/ast" + "github.com/openziti/foundation/storage/boltz" +) + +func (m *Migrations) addIdentityIdToSessions(step *boltz.MigrationStep) { + cursor := m.stores.Session.IterateIds(step.Ctx.Tx(), ast.BoolNodeTrue) + + fieldChecker := boltz.MapFieldChecker{ + FieldSessionIdentity: struct{}{}, + } + + for cursor.IsValid() { + sessionId := string(cursor.Current()) + session, err := m.stores.Session.LoadOneById(step.Ctx.Tx(), sessionId) + + if err != nil { + step.SetError(fmt.Errorf("could no load session by id [%s]: %v", sessionId, err)) + return + } + + if session == nil { + step.SetError(fmt.Errorf("session [%s] load did not error but session is null", sessionId)) + return + } + + if session.IdentityId == "" { + if apiSession, err := m.stores.ApiSession.LoadOneById(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 { + step.SetError(fmt.Errorf("could not update session [%s]: %v", session.Id, err)) + return + } + } + } + } + + cursor.Next() + } + + cursor = m.stores.Session.IterateIds(step.Ctx.Tx(), ast.BoolNodeTrue) + + for cursor.IsValid() { + sessionId := string(cursor.Current()) + session, _ := m.stores.Session.LoadOneById(step.Ctx.Tx(), sessionId) + + fmt.Printf("%+v\n", session) + + cursor.Next() + } + +} diff --git a/controller/persistence/migrations.go b/controller/persistence/migrations.go index 145bef4ed..7d5c87281 100644 --- a/controller/persistence/migrations.go +++ b/controller/persistence/migrations.go @@ -22,7 +22,7 @@ import ( ) const ( - CurrentDbVersion = 23 + CurrentDbVersion = 24 FieldVersion = "version" ) @@ -100,6 +100,10 @@ func (m *Migrations) migrate(step *boltz.MigrationStep) int { m.addProcessMultiPostureCheck(step) } + if step.CurrentVersion < 24 { + m.addIdentityIdToSessions(step) + } + // current version if step.CurrentVersion <= CurrentDbVersion { return CurrentDbVersion diff --git a/controller/persistence/session_store.go b/controller/persistence/session_store.go index 0b6d9429b..09b5cd2fe 100644 --- a/controller/persistence/session_store.go +++ b/controller/persistence/session_store.go @@ -62,7 +62,7 @@ func (entity *Session) LoadValues(_ boltz.CrudStore, bucket *boltz.TypedBucket) entity.Token = bucket.GetStringOrError(FieldSessionToken) entity.ApiSessionId = bucket.GetStringOrError(FieldSessionApiSession) entity.ServiceId = bucket.GetStringOrError(FieldSessionService) - entity.IdentityId = bucket.GetStringOrError(FieldSessionIdentity) + entity.IdentityId = bucket.GetStringWithDefault(FieldSessionIdentity, "") entity.Type = bucket.GetStringWithDefault(FieldSessionType, "Dial") entity.ServicePolicies = bucket.GetStringList(FieldSessionServicePolicies) } From 02b7c103ec129b003a0886281fb1fe70931438d8 Mon Sep 17 00:00:00 2001 From: Andrew Martinez Date: Fri, 3 Sep 2021 09:52:43 -0400 Subject: [PATCH 2/3] adds codeowners --- .github/CODEOWNERS | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .github/CODEOWNERS diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 000000000..31c103425 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,3 @@ +# see: +# https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/creating-a-repository-on-github/about-code-owners +* @openziti/maintainers From 17b82de1fd58ca56ad08c43a3b8d4e35ed3664e8 Mon Sep 17 00:00:00 2001 From: Andrew Martinez Date: Fri, 3 Sep 2021 09:55:39 -0400 Subject: [PATCH 3/3] remove debug output --- controller/persistence/migration_v24.go | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/controller/persistence/migration_v24.go b/controller/persistence/migration_v24.go index fb8c4af4b..3368d454a 100644 --- a/controller/persistence/migration_v24.go +++ b/controller/persistence/migration_v24.go @@ -41,16 +41,4 @@ func (m *Migrations) addIdentityIdToSessions(step *boltz.MigrationStep) { cursor.Next() } - - cursor = m.stores.Session.IterateIds(step.Ctx.Tx(), ast.BoolNodeTrue) - - for cursor.IsValid() { - sessionId := string(cursor.Current()) - session, _ := m.stores.Session.LoadOneById(step.Ctx.Tx(), sessionId) - - fmt.Printf("%+v\n", session) - - cursor.Next() - } - }