mirror of
https://github.com/openziti/ziti.git
synced 2026-10-14 16:19:57 +00:00
Merge pull request #766 from openziti/add.session.identityId.migration
Add session identiyId migration
This commit is contained in:
@@ -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
|
||||
@@ -0,0 +1,44 @@
|
||||
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()
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user