Skip to content

Commit eabf4de

Browse files
f - session: add migration code from kvdb to SQL
1 parent d2b1401 commit eabf4de

File tree

2 files changed

+0
-37
lines changed

2 files changed

+0
-37
lines changed

session/sql_migration.go

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ func migrateSessionsToSQLAndValidate(ctx context.Context,
111111

112112
overrideSessionTimeZone(kvSession)
113113
overrideSessionTimeZone(migratedSession)
114-
overrideMacaroonRecipe(kvSession, migratedSession)
115114

116115
if !reflect.DeepEqual(kvSession, migratedSession) {
117116
diff := difflib.UnifiedDiff{
@@ -329,33 +328,3 @@ func overrideSessionTimeZone(session *Session) {
329328
session.RevokedAt = fixTime(session.RevokedAt)
330329
}
331330
}
332-
333-
// overrideMacaroonRecipe overrides the MacaroonRecipe for the SQL session in a
334-
// certain scenario:
335-
// In the bbolt store, a session can have a non-nil macaroon struct, despite
336-
// both the permissions and caveats being nil. There is no way to represent this
337-
// in the SQL store, as the macaroon permissions and caveats are separate
338-
// tables. Therefore, in the scenario where a MacaroonRecipe exists for the
339-
// bbolt version, but both the permissions and caveats are nil, we override the
340-
// MacaroonRecipe for the SQL version and set it to a MacaroonRecipe with
341-
// nil permissions and caveats. This is needed to ensure that the deep equals
342-
// check in the migration validation does not fail in this scenario.
343-
// Additionally, if either the permissions or caveats aren't set, for the
344-
// MacaroonRecipe, that is represented as empty array in the SQL store, but
345-
// as nil in the bbolt store. Therefore, we also override the permissions
346-
// or caveats to nil for the migrated session in that scenario, so that the
347-
// deep equals check does not fail in this scenario either.
348-
func overrideMacaroonRecipe(kvSession *Session, migratedSession *Session) {
349-
if kvSession.MacaroonRecipe != nil {
350-
kvPerms := kvSession.MacaroonRecipe.Permissions
351-
kvCaveats := kvSession.MacaroonRecipe.Caveats
352-
353-
if kvPerms == nil && kvCaveats == nil {
354-
migratedSession.MacaroonRecipe = &MacaroonRecipe{}
355-
} else if kvPerms == nil {
356-
migratedSession.MacaroonRecipe.Permissions = nil
357-
} else if kvCaveats == nil {
358-
migratedSession.MacaroonRecipe.Caveats = nil
359-
}
360-
}
361-
}

session/sql_migration_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,6 @@ func TestSessionsStoreMigration(t *testing.T) {
7373
)
7474
require.NoError(t, err)
7575

76-
// Since the SQL store can't represent a session with
77-
// a non-nil MacaroonRecipe, but with nil caveats and
78-
// perms, we need to override the macaroon recipe if the
79-
// kvSession has such a recipe stored.
80-
overrideMacaroonRecipe(kvSession, sqlSession)
81-
8276
assertEqualSessions(t, kvSession, sqlSession)
8377
}
8478

0 commit comments

Comments
 (0)