feat(relational): implement session repository (#11109)

# Which Problems Are Solved

As part of going to a relation storage model, we need to implement the
repository for handling sessions and their events.

# How the Problems Are Solved

- Adds a migration step to create the necessary tables and types in the
database.
- Adds the repository implementation for sessions.
- Implements a projection handler for session events to handle the
events written by the old command handlers.
- Updates the `Session` type and `SessionRepository` interface:
  - added `CreatorID`
  - Adjusted `Delete` method to return amount of affected columns
  - Removed sub-repository clumns from the main interface
- Added `CreatorIDCondition`, `ExpirationCondition`, `ExistsFactor` and
`ExistsMetadata`
  - Removed `SetUserAgent`
- Methods of `SessionFactor` and `SessionChallenge` have been made
public
- fixed enumer on `SessionFactorType`
- Adds a `JSON` type to the repository package to easy can JSON columns,
resp. jsonb object inside a property of a `JSONArray` object.
- Adds a `NoChange` interface, which can be implemented to signal that a
`Change` interface implementation is not writing any changes to the
statement builder, e.g. `CTEChange`

# Additional Changes

- Fixes the operators enums. `TextOperations` had wrong comments and
`NumberOperations` additionally also had from comparisons.
- Fixes downgrade of migration step 008.

# Additional Context

- closes https://github.com/zitadel/zitadel/issues/10212
This commit is contained in:
Livio Spring
2026-01-06 08:08:11 +01:00
committed by GitHub
parent 5f34d1af8f
commit 4e6f68c511
25 changed files with 4305 additions and 387 deletions
+216 -254
View File
@@ -23,7 +23,6 @@ import (
type MockSessionRepository struct {
ctrl *gomock.Controller
recorder *MockSessionRepositoryMockRecorder
isgomock struct{}
}
// MockSessionRepositoryMockRecorder is the mock recorder for MockSessionRepository.
@@ -44,17 +43,17 @@ func (m *MockSessionRepository) EXPECT() *MockSessionRepositoryMockRecorder {
}
// ClearFactor mocks base method.
func (m *MockSessionRepository) ClearFactor(factor domain.SessionFactorType) database.Change {
func (m *MockSessionRepository) ClearFactor(arg0 domain.SessionFactorType) database.Change {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ClearFactor", factor)
ret := m.ctrl.Call(m, "ClearFactor", arg0)
ret0, _ := ret[0].(database.Change)
return ret0
}
// ClearFactor indicates an expected call of ClearFactor.
func (mr *MockSessionRepositoryMockRecorder) ClearFactor(factor any) *MockSessionRepositoryClearFactorCall {
func (mr *MockSessionRepositoryMockRecorder) ClearFactor(arg0 any) *MockSessionRepositoryClearFactorCall {
mr.mock.ctrl.T.Helper()
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ClearFactor", reflect.TypeOf((*MockSessionRepository)(nil).ClearFactor), factor)
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ClearFactor", reflect.TypeOf((*MockSessionRepository)(nil).ClearFactor), arg0)
return &MockSessionRepositoryClearFactorCall{Call: call}
}
@@ -82,17 +81,17 @@ func (c *MockSessionRepositoryClearFactorCall) DoAndReturn(f func(domain.Session
}
// Create mocks base method.
func (m *MockSessionRepository) Create(ctx context.Context, client database.QueryExecutor, user *domain.Session) error {
func (m *MockSessionRepository) Create(arg0 context.Context, arg1 database.QueryExecutor, arg2 *domain.Session) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Create", ctx, client, user)
ret := m.ctrl.Call(m, "Create", arg0, arg1, arg2)
ret0, _ := ret[0].(error)
return ret0
}
// Create indicates an expected call of Create.
func (mr *MockSessionRepositoryMockRecorder) Create(ctx, client, user any) *MockSessionRepositoryCreateCall {
func (mr *MockSessionRepositoryMockRecorder) Create(arg0, arg1, arg2 any) *MockSessionRepositoryCreateCall {
mr.mock.ctrl.T.Helper()
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*MockSessionRepository)(nil).Create), ctx, client, user)
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*MockSessionRepository)(nil).Create), arg0, arg1, arg2)
return &MockSessionRepositoryCreateCall{Call: call}
}
@@ -158,17 +157,17 @@ func (c *MockSessionRepositoryCreatedAtColumnCall) DoAndReturn(f func() database
}
// CreatedAtCondition mocks base method.
func (m *MockSessionRepository) CreatedAtCondition(op database.NumberOperation, createdAt time.Time) database.Condition {
func (m *MockSessionRepository) CreatedAtCondition(arg0 database.NumberOperation, arg1 time.Time) database.Condition {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "CreatedAtCondition", op, createdAt)
ret := m.ctrl.Call(m, "CreatedAtCondition", arg0, arg1)
ret0, _ := ret[0].(database.Condition)
return ret0
}
// CreatedAtCondition indicates an expected call of CreatedAtCondition.
func (mr *MockSessionRepositoryMockRecorder) CreatedAtCondition(op, createdAt any) *MockSessionRepositoryCreatedAtConditionCall {
func (mr *MockSessionRepositoryMockRecorder) CreatedAtCondition(arg0, arg1 any) *MockSessionRepositoryCreatedAtConditionCall {
mr.mock.ctrl.T.Helper()
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreatedAtCondition", reflect.TypeOf((*MockSessionRepository)(nil).CreatedAtCondition), op, createdAt)
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreatedAtCondition", reflect.TypeOf((*MockSessionRepository)(nil).CreatedAtCondition), arg0, arg1)
return &MockSessionRepositoryCreatedAtConditionCall{Call: call}
}
@@ -195,18 +194,57 @@ func (c *MockSessionRepositoryCreatedAtConditionCall) DoAndReturn(f func(databas
return c
}
// Delete mocks base method.
func (m *MockSessionRepository) Delete(ctx context.Context, client database.QueryExecutor, condition database.Condition) error {
// CreatorIDCondition mocks base method.
func (m *MockSessionRepository) CreatorIDCondition(arg0 string) database.Condition {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Delete", ctx, client, condition)
ret0, _ := ret[0].(error)
ret := m.ctrl.Call(m, "CreatorIDCondition", arg0)
ret0, _ := ret[0].(database.Condition)
return ret0
}
// Delete indicates an expected call of Delete.
func (mr *MockSessionRepositoryMockRecorder) Delete(ctx, client, condition any) *MockSessionRepositoryDeleteCall {
// CreatorIDCondition indicates an expected call of CreatorIDCondition.
func (mr *MockSessionRepositoryMockRecorder) CreatorIDCondition(arg0 any) *MockSessionRepositoryCreatorIDConditionCall {
mr.mock.ctrl.T.Helper()
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockSessionRepository)(nil).Delete), ctx, client, condition)
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreatorIDCondition", reflect.TypeOf((*MockSessionRepository)(nil).CreatorIDCondition), arg0)
return &MockSessionRepositoryCreatorIDConditionCall{Call: call}
}
// MockSessionRepositoryCreatorIDConditionCall wrap *gomock.Call
type MockSessionRepositoryCreatorIDConditionCall struct {
*gomock.Call
}
// Return rewrite *gomock.Call.Return
func (c *MockSessionRepositoryCreatorIDConditionCall) Return(arg0 database.Condition) *MockSessionRepositoryCreatorIDConditionCall {
c.Call = c.Call.Return(arg0)
return c
}
// Do rewrite *gomock.Call.Do
func (c *MockSessionRepositoryCreatorIDConditionCall) Do(f func(string) database.Condition) *MockSessionRepositoryCreatorIDConditionCall {
c.Call = c.Call.Do(f)
return c
}
// DoAndReturn rewrite *gomock.Call.DoAndReturn
func (c *MockSessionRepositoryCreatorIDConditionCall) DoAndReturn(f func(string) database.Condition) *MockSessionRepositoryCreatorIDConditionCall {
c.Call = c.Call.DoAndReturn(f)
return c
}
// Delete mocks base method.
func (m *MockSessionRepository) Delete(arg0 context.Context, arg1 database.QueryExecutor, arg2 database.Condition) (int64, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Delete", arg0, arg1, arg2)
ret0, _ := ret[0].(int64)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// Delete indicates an expected call of Delete.
func (mr *MockSessionRepositoryMockRecorder) Delete(arg0, arg1, arg2 any) *MockSessionRepositoryDeleteCall {
mr.mock.ctrl.T.Helper()
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockSessionRepository)(nil).Delete), arg0, arg1, arg2)
return &MockSessionRepositoryDeleteCall{Call: call}
}
@@ -216,19 +254,95 @@ type MockSessionRepositoryDeleteCall struct {
}
// Return rewrite *gomock.Call.Return
func (c *MockSessionRepositoryDeleteCall) Return(arg0 error) *MockSessionRepositoryDeleteCall {
c.Call = c.Call.Return(arg0)
func (c *MockSessionRepositoryDeleteCall) Return(arg0 int64, arg1 error) *MockSessionRepositoryDeleteCall {
c.Call = c.Call.Return(arg0, arg1)
return c
}
// Do rewrite *gomock.Call.Do
func (c *MockSessionRepositoryDeleteCall) Do(f func(context.Context, database.QueryExecutor, database.Condition) error) *MockSessionRepositoryDeleteCall {
func (c *MockSessionRepositoryDeleteCall) Do(f func(context.Context, database.QueryExecutor, database.Condition) (int64, error)) *MockSessionRepositoryDeleteCall {
c.Call = c.Call.Do(f)
return c
}
// DoAndReturn rewrite *gomock.Call.DoAndReturn
func (c *MockSessionRepositoryDeleteCall) DoAndReturn(f func(context.Context, database.QueryExecutor, database.Condition) error) *MockSessionRepositoryDeleteCall {
func (c *MockSessionRepositoryDeleteCall) DoAndReturn(f func(context.Context, database.QueryExecutor, database.Condition) (int64, error)) *MockSessionRepositoryDeleteCall {
c.Call = c.Call.DoAndReturn(f)
return c
}
// ExistsFactor mocks base method.
func (m *MockSessionRepository) ExistsFactor(arg0 database.Condition) database.Condition {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ExistsFactor", arg0)
ret0, _ := ret[0].(database.Condition)
return ret0
}
// ExistsFactor indicates an expected call of ExistsFactor.
func (mr *MockSessionRepositoryMockRecorder) ExistsFactor(arg0 any) *MockSessionRepositoryExistsFactorCall {
mr.mock.ctrl.T.Helper()
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExistsFactor", reflect.TypeOf((*MockSessionRepository)(nil).ExistsFactor), arg0)
return &MockSessionRepositoryExistsFactorCall{Call: call}
}
// MockSessionRepositoryExistsFactorCall wrap *gomock.Call
type MockSessionRepositoryExistsFactorCall struct {
*gomock.Call
}
// Return rewrite *gomock.Call.Return
func (c *MockSessionRepositoryExistsFactorCall) Return(arg0 database.Condition) *MockSessionRepositoryExistsFactorCall {
c.Call = c.Call.Return(arg0)
return c
}
// Do rewrite *gomock.Call.Do
func (c *MockSessionRepositoryExistsFactorCall) Do(f func(database.Condition) database.Condition) *MockSessionRepositoryExistsFactorCall {
c.Call = c.Call.Do(f)
return c
}
// DoAndReturn rewrite *gomock.Call.DoAndReturn
func (c *MockSessionRepositoryExistsFactorCall) DoAndReturn(f func(database.Condition) database.Condition) *MockSessionRepositoryExistsFactorCall {
c.Call = c.Call.DoAndReturn(f)
return c
}
// ExistsMetadata mocks base method.
func (m *MockSessionRepository) ExistsMetadata(arg0 database.Condition) database.Condition {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ExistsMetadata", arg0)
ret0, _ := ret[0].(database.Condition)
return ret0
}
// ExistsMetadata indicates an expected call of ExistsMetadata.
func (mr *MockSessionRepositoryMockRecorder) ExistsMetadata(arg0 any) *MockSessionRepositoryExistsMetadataCall {
mr.mock.ctrl.T.Helper()
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExistsMetadata", reflect.TypeOf((*MockSessionRepository)(nil).ExistsMetadata), arg0)
return &MockSessionRepositoryExistsMetadataCall{Call: call}
}
// MockSessionRepositoryExistsMetadataCall wrap *gomock.Call
type MockSessionRepositoryExistsMetadataCall struct {
*gomock.Call
}
// Return rewrite *gomock.Call.Return
func (c *MockSessionRepositoryExistsMetadataCall) Return(arg0 database.Condition) *MockSessionRepositoryExistsMetadataCall {
c.Call = c.Call.Return(arg0)
return c
}
// Do rewrite *gomock.Call.Do
func (c *MockSessionRepositoryExistsMetadataCall) Do(f func(database.Condition) database.Condition) *MockSessionRepositoryExistsMetadataCall {
c.Call = c.Call.Do(f)
return c
}
// DoAndReturn rewrite *gomock.Call.DoAndReturn
func (c *MockSessionRepositoryExistsMetadataCall) DoAndReturn(f func(database.Condition) database.Condition) *MockSessionRepositoryExistsMetadataCall {
c.Call = c.Call.DoAndReturn(f)
return c
}
@@ -271,40 +385,40 @@ func (c *MockSessionRepositoryExpirationColumnCall) DoAndReturn(f func() databas
return c
}
// FactorColumns mocks base method.
func (m *MockSessionRepository) FactorColumns() domain.SessionFactorColumns {
// ExpirationCondition mocks base method.
func (m *MockSessionRepository) ExpirationCondition(arg0 database.NumberOperation, arg1 time.Time) database.Condition {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "FactorColumns")
ret0, _ := ret[0].(domain.SessionFactorColumns)
ret := m.ctrl.Call(m, "ExpirationCondition", arg0, arg1)
ret0, _ := ret[0].(database.Condition)
return ret0
}
// FactorColumns indicates an expected call of FactorColumns.
func (mr *MockSessionRepositoryMockRecorder) FactorColumns() *MockSessionRepositoryFactorColumnsCall {
// ExpirationCondition indicates an expected call of ExpirationCondition.
func (mr *MockSessionRepositoryMockRecorder) ExpirationCondition(arg0, arg1 any) *MockSessionRepositoryExpirationConditionCall {
mr.mock.ctrl.T.Helper()
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FactorColumns", reflect.TypeOf((*MockSessionRepository)(nil).FactorColumns))
return &MockSessionRepositoryFactorColumnsCall{Call: call}
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExpirationCondition", reflect.TypeOf((*MockSessionRepository)(nil).ExpirationCondition), arg0, arg1)
return &MockSessionRepositoryExpirationConditionCall{Call: call}
}
// MockSessionRepositoryFactorColumnsCall wrap *gomock.Call
type MockSessionRepositoryFactorColumnsCall struct {
// MockSessionRepositoryExpirationConditionCall wrap *gomock.Call
type MockSessionRepositoryExpirationConditionCall struct {
*gomock.Call
}
// Return rewrite *gomock.Call.Return
func (c *MockSessionRepositoryFactorColumnsCall) Return(arg0 domain.SessionFactorColumns) *MockSessionRepositoryFactorColumnsCall {
func (c *MockSessionRepositoryExpirationConditionCall) Return(arg0 database.Condition) *MockSessionRepositoryExpirationConditionCall {
c.Call = c.Call.Return(arg0)
return c
}
// Do rewrite *gomock.Call.Do
func (c *MockSessionRepositoryFactorColumnsCall) Do(f func() domain.SessionFactorColumns) *MockSessionRepositoryFactorColumnsCall {
func (c *MockSessionRepositoryExpirationConditionCall) Do(f func(database.NumberOperation, time.Time) database.Condition) *MockSessionRepositoryExpirationConditionCall {
c.Call = c.Call.Do(f)
return c
}
// DoAndReturn rewrite *gomock.Call.DoAndReturn
func (c *MockSessionRepositoryFactorColumnsCall) DoAndReturn(f func() domain.SessionFactorColumns) *MockSessionRepositoryFactorColumnsCall {
func (c *MockSessionRepositoryExpirationConditionCall) DoAndReturn(f func(database.NumberOperation, time.Time) database.Condition) *MockSessionRepositoryExpirationConditionCall {
c.Call = c.Call.DoAndReturn(f)
return c
}
@@ -348,10 +462,10 @@ func (c *MockSessionRepositoryFactorConditionsCall) DoAndReturn(f func() domain.
}
// Get mocks base method.
func (m *MockSessionRepository) Get(ctx context.Context, client database.QueryExecutor, opts ...database.QueryOption) (*domain.Session, error) {
func (m *MockSessionRepository) Get(arg0 context.Context, arg1 database.QueryExecutor, arg2 ...database.QueryOption) (*domain.Session, error) {
m.ctrl.T.Helper()
varargs := []any{ctx, client}
for _, a := range opts {
varargs := []any{arg0, arg1}
for _, a := range arg2 {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "Get", varargs...)
@@ -361,9 +475,9 @@ func (m *MockSessionRepository) Get(ctx context.Context, client database.QueryEx
}
// Get indicates an expected call of Get.
func (mr *MockSessionRepositoryMockRecorder) Get(ctx, client any, opts ...any) *MockSessionRepositoryGetCall {
func (mr *MockSessionRepositoryMockRecorder) Get(arg0, arg1 any, arg2 ...any) *MockSessionRepositoryGetCall {
mr.mock.ctrl.T.Helper()
varargs := append([]any{ctx, client}, opts...)
varargs := append([]any{arg0, arg1}, arg2...)
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockSessionRepository)(nil).Get), varargs...)
return &MockSessionRepositoryGetCall{Call: call}
}
@@ -430,17 +544,17 @@ func (c *MockSessionRepositoryIDColumnCall) DoAndReturn(f func() database.Column
}
// IDCondition mocks base method.
func (m *MockSessionRepository) IDCondition(sessionID string) database.Condition {
func (m *MockSessionRepository) IDCondition(arg0 string) database.Condition {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "IDCondition", sessionID)
ret := m.ctrl.Call(m, "IDCondition", arg0)
ret0, _ := ret[0].(database.Condition)
return ret0
}
// IDCondition indicates an expected call of IDCondition.
func (mr *MockSessionRepositoryMockRecorder) IDCondition(sessionID any) *MockSessionRepositoryIDConditionCall {
func (mr *MockSessionRepositoryMockRecorder) IDCondition(arg0 any) *MockSessionRepositoryIDConditionCall {
mr.mock.ctrl.T.Helper()
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IDCondition", reflect.TypeOf((*MockSessionRepository)(nil).IDCondition), sessionID)
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IDCondition", reflect.TypeOf((*MockSessionRepository)(nil).IDCondition), arg0)
return &MockSessionRepositoryIDConditionCall{Call: call}
}
@@ -506,17 +620,17 @@ func (c *MockSessionRepositoryInstanceIDColumnCall) DoAndReturn(f func() databas
}
// InstanceIDCondition mocks base method.
func (m *MockSessionRepository) InstanceIDCondition(instanceID string) database.Condition {
func (m *MockSessionRepository) InstanceIDCondition(arg0 string) database.Condition {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "InstanceIDCondition", instanceID)
ret := m.ctrl.Call(m, "InstanceIDCondition", arg0)
ret0, _ := ret[0].(database.Condition)
return ret0
}
// InstanceIDCondition indicates an expected call of InstanceIDCondition.
func (mr *MockSessionRepositoryMockRecorder) InstanceIDCondition(instanceID any) *MockSessionRepositoryInstanceIDConditionCall {
func (mr *MockSessionRepositoryMockRecorder) InstanceIDCondition(arg0 any) *MockSessionRepositoryInstanceIDConditionCall {
mr.mock.ctrl.T.Helper()
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InstanceIDCondition", reflect.TypeOf((*MockSessionRepository)(nil).InstanceIDCondition), instanceID)
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InstanceIDCondition", reflect.TypeOf((*MockSessionRepository)(nil).InstanceIDCondition), arg0)
return &MockSessionRepositoryInstanceIDConditionCall{Call: call}
}
@@ -582,10 +696,10 @@ func (c *MockSessionRepositoryLifetimeColumnCall) DoAndReturn(f func() database.
}
// List mocks base method.
func (m *MockSessionRepository) List(ctx context.Context, client database.QueryExecutor, opts ...database.QueryOption) ([]*domain.Session, error) {
func (m *MockSessionRepository) List(arg0 context.Context, arg1 database.QueryExecutor, arg2 ...database.QueryOption) ([]*domain.Session, error) {
m.ctrl.T.Helper()
varargs := []any{ctx, client}
for _, a := range opts {
varargs := []any{arg0, arg1}
for _, a := range arg2 {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "List", varargs...)
@@ -595,9 +709,9 @@ func (m *MockSessionRepository) List(ctx context.Context, client database.QueryE
}
// List indicates an expected call of List.
func (mr *MockSessionRepositoryMockRecorder) List(ctx, client any, opts ...any) *MockSessionRepositoryListCall {
func (mr *MockSessionRepositoryMockRecorder) List(arg0, arg1 any, arg2 ...any) *MockSessionRepositoryListCall {
mr.mock.ctrl.T.Helper()
varargs := append([]any{ctx, client}, opts...)
varargs := append([]any{arg0, arg1}, arg2...)
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "List", reflect.TypeOf((*MockSessionRepository)(nil).List), varargs...)
return &MockSessionRepositoryListCall{Call: call}
}
@@ -625,44 +739,6 @@ func (c *MockSessionRepositoryListCall) DoAndReturn(f func(context.Context, data
return c
}
// MetadataColumns mocks base method.
func (m *MockSessionRepository) MetadataColumns() domain.SessionMetadataColumns {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "MetadataColumns")
ret0, _ := ret[0].(domain.SessionMetadataColumns)
return ret0
}
// MetadataColumns indicates an expected call of MetadataColumns.
func (mr *MockSessionRepositoryMockRecorder) MetadataColumns() *MockSessionRepositoryMetadataColumnsCall {
mr.mock.ctrl.T.Helper()
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "MetadataColumns", reflect.TypeOf((*MockSessionRepository)(nil).MetadataColumns))
return &MockSessionRepositoryMetadataColumnsCall{Call: call}
}
// MockSessionRepositoryMetadataColumnsCall wrap *gomock.Call
type MockSessionRepositoryMetadataColumnsCall struct {
*gomock.Call
}
// Return rewrite *gomock.Call.Return
func (c *MockSessionRepositoryMetadataColumnsCall) Return(arg0 domain.SessionMetadataColumns) *MockSessionRepositoryMetadataColumnsCall {
c.Call = c.Call.Return(arg0)
return c
}
// Do rewrite *gomock.Call.Do
func (c *MockSessionRepositoryMetadataColumnsCall) Do(f func() domain.SessionMetadataColumns) *MockSessionRepositoryMetadataColumnsCall {
c.Call = c.Call.Do(f)
return c
}
// DoAndReturn rewrite *gomock.Call.DoAndReturn
func (c *MockSessionRepositoryMetadataColumnsCall) DoAndReturn(f func() domain.SessionMetadataColumns) *MockSessionRepositoryMetadataColumnsCall {
c.Call = c.Call.DoAndReturn(f)
return c
}
// MetadataConditions mocks base method.
func (m *MockSessionRepository) MetadataConditions() domain.SessionMetadataConditions {
m.ctrl.T.Helper()
@@ -740,17 +816,17 @@ func (c *MockSessionRepositoryPrimaryKeyColumnsCall) DoAndReturn(f func() []data
}
// PrimaryKeyCondition mocks base method.
func (m *MockSessionRepository) PrimaryKeyCondition(instanceID, sessionID string) database.Condition {
func (m *MockSessionRepository) PrimaryKeyCondition(arg0, arg1 string) database.Condition {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "PrimaryKeyCondition", instanceID, sessionID)
ret := m.ctrl.Call(m, "PrimaryKeyCondition", arg0, arg1)
ret0, _ := ret[0].(database.Condition)
return ret0
}
// PrimaryKeyCondition indicates an expected call of PrimaryKeyCondition.
func (mr *MockSessionRepositoryMockRecorder) PrimaryKeyCondition(instanceID, sessionID any) *MockSessionRepositoryPrimaryKeyConditionCall {
func (mr *MockSessionRepositoryMockRecorder) PrimaryKeyCondition(arg0, arg1 any) *MockSessionRepositoryPrimaryKeyConditionCall {
mr.mock.ctrl.T.Helper()
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PrimaryKeyCondition", reflect.TypeOf((*MockSessionRepository)(nil).PrimaryKeyCondition), instanceID, sessionID)
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PrimaryKeyCondition", reflect.TypeOf((*MockSessionRepository)(nil).PrimaryKeyCondition), arg0, arg1)
return &MockSessionRepositoryPrimaryKeyConditionCall{Call: call}
}
@@ -778,17 +854,17 @@ func (c *MockSessionRepositoryPrimaryKeyConditionCall) DoAndReturn(f func(string
}
// SetChallenge mocks base method.
func (m *MockSessionRepository) SetChallenge(challenge domain.SessionChallenge) database.Change {
func (m *MockSessionRepository) SetChallenge(arg0 domain.SessionChallenge) database.Change {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SetChallenge", challenge)
ret := m.ctrl.Call(m, "SetChallenge", arg0)
ret0, _ := ret[0].(database.Change)
return ret0
}
// SetChallenge indicates an expected call of SetChallenge.
func (mr *MockSessionRepositoryMockRecorder) SetChallenge(challenge any) *MockSessionRepositorySetChallengeCall {
func (mr *MockSessionRepositoryMockRecorder) SetChallenge(arg0 any) *MockSessionRepositorySetChallengeCall {
mr.mock.ctrl.T.Helper()
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetChallenge", reflect.TypeOf((*MockSessionRepository)(nil).SetChallenge), challenge)
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetChallenge", reflect.TypeOf((*MockSessionRepository)(nil).SetChallenge), arg0)
return &MockSessionRepositorySetChallengeCall{Call: call}
}
@@ -816,17 +892,17 @@ func (c *MockSessionRepositorySetChallengeCall) DoAndReturn(f func(domain.Sessio
}
// SetFactor mocks base method.
func (m *MockSessionRepository) SetFactor(factor domain.SessionFactor) database.Change {
func (m *MockSessionRepository) SetFactor(arg0 domain.SessionFactor) database.Change {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SetFactor", factor)
ret := m.ctrl.Call(m, "SetFactor", arg0)
ret0, _ := ret[0].(database.Change)
return ret0
}
// SetFactor indicates an expected call of SetFactor.
func (mr *MockSessionRepositoryMockRecorder) SetFactor(factor any) *MockSessionRepositorySetFactorCall {
func (mr *MockSessionRepositoryMockRecorder) SetFactor(arg0 any) *MockSessionRepositorySetFactorCall {
mr.mock.ctrl.T.Helper()
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetFactor", reflect.TypeOf((*MockSessionRepository)(nil).SetFactor), factor)
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetFactor", reflect.TypeOf((*MockSessionRepository)(nil).SetFactor), arg0)
return &MockSessionRepositorySetFactorCall{Call: call}
}
@@ -854,17 +930,17 @@ func (c *MockSessionRepositorySetFactorCall) DoAndReturn(f func(domain.SessionFa
}
// SetLifetime mocks base method.
func (m *MockSessionRepository) SetLifetime(lifetime time.Duration) database.Change {
func (m *MockSessionRepository) SetLifetime(arg0 time.Duration) database.Change {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SetLifetime", lifetime)
ret := m.ctrl.Call(m, "SetLifetime", arg0)
ret0, _ := ret[0].(database.Change)
return ret0
}
// SetLifetime indicates an expected call of SetLifetime.
func (mr *MockSessionRepositoryMockRecorder) SetLifetime(lifetime any) *MockSessionRepositorySetLifetimeCall {
func (mr *MockSessionRepositoryMockRecorder) SetLifetime(arg0 any) *MockSessionRepositorySetLifetimeCall {
mr.mock.ctrl.T.Helper()
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetLifetime", reflect.TypeOf((*MockSessionRepository)(nil).SetLifetime), lifetime)
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetLifetime", reflect.TypeOf((*MockSessionRepository)(nil).SetLifetime), arg0)
return &MockSessionRepositorySetLifetimeCall{Call: call}
}
@@ -892,17 +968,17 @@ func (c *MockSessionRepositorySetLifetimeCall) DoAndReturn(f func(time.Duration)
}
// SetMetadata mocks base method.
func (m *MockSessionRepository) SetMetadata(metadata []domain.SessionMetadata) database.Change {
func (m *MockSessionRepository) SetMetadata(arg0 []*domain.SessionMetadata) database.Change {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SetMetadata", metadata)
ret := m.ctrl.Call(m, "SetMetadata", arg0)
ret0, _ := ret[0].(database.Change)
return ret0
}
// SetMetadata indicates an expected call of SetMetadata.
func (mr *MockSessionRepositoryMockRecorder) SetMetadata(metadata any) *MockSessionRepositorySetMetadataCall {
func (mr *MockSessionRepositoryMockRecorder) SetMetadata(arg0 any) *MockSessionRepositorySetMetadataCall {
mr.mock.ctrl.T.Helper()
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetMetadata", reflect.TypeOf((*MockSessionRepository)(nil).SetMetadata), metadata)
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetMetadata", reflect.TypeOf((*MockSessionRepository)(nil).SetMetadata), arg0)
return &MockSessionRepositorySetMetadataCall{Call: call}
}
@@ -918,29 +994,29 @@ func (c *MockSessionRepositorySetMetadataCall) Return(arg0 database.Change) *Moc
}
// Do rewrite *gomock.Call.Do
func (c *MockSessionRepositorySetMetadataCall) Do(f func([]domain.SessionMetadata) database.Change) *MockSessionRepositorySetMetadataCall {
func (c *MockSessionRepositorySetMetadataCall) Do(f func([]*domain.SessionMetadata) database.Change) *MockSessionRepositorySetMetadataCall {
c.Call = c.Call.Do(f)
return c
}
// DoAndReturn rewrite *gomock.Call.DoAndReturn
func (c *MockSessionRepositorySetMetadataCall) DoAndReturn(f func([]domain.SessionMetadata) database.Change) *MockSessionRepositorySetMetadataCall {
func (c *MockSessionRepositorySetMetadataCall) DoAndReturn(f func([]*domain.SessionMetadata) database.Change) *MockSessionRepositorySetMetadataCall {
c.Call = c.Call.DoAndReturn(f)
return c
}
// SetToken mocks base method.
func (m *MockSessionRepository) SetToken(token string) database.Change {
func (m *MockSessionRepository) SetToken(arg0 string) database.Change {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SetToken", token)
ret := m.ctrl.Call(m, "SetToken", arg0)
ret0, _ := ret[0].(database.Change)
return ret0
}
// SetToken indicates an expected call of SetToken.
func (mr *MockSessionRepositoryMockRecorder) SetToken(token any) *MockSessionRepositorySetTokenCall {
func (mr *MockSessionRepositoryMockRecorder) SetToken(arg0 any) *MockSessionRepositorySetTokenCall {
mr.mock.ctrl.T.Helper()
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetToken", reflect.TypeOf((*MockSessionRepository)(nil).SetToken), token)
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetToken", reflect.TypeOf((*MockSessionRepository)(nil).SetToken), arg0)
return &MockSessionRepositorySetTokenCall{Call: call}
}
@@ -968,17 +1044,17 @@ func (c *MockSessionRepositorySetTokenCall) DoAndReturn(f func(string) database.
}
// SetUpdatedAt mocks base method.
func (m *MockSessionRepository) SetUpdatedAt(updatedAt time.Time) database.Change {
func (m *MockSessionRepository) SetUpdatedAt(arg0 time.Time) database.Change {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SetUpdatedAt", updatedAt)
ret := m.ctrl.Call(m, "SetUpdatedAt", arg0)
ret0, _ := ret[0].(database.Change)
return ret0
}
// SetUpdatedAt indicates an expected call of SetUpdatedAt.
func (mr *MockSessionRepositoryMockRecorder) SetUpdatedAt(updatedAt any) *MockSessionRepositorySetUpdatedAtCall {
func (mr *MockSessionRepositoryMockRecorder) SetUpdatedAt(arg0 any) *MockSessionRepositorySetUpdatedAtCall {
mr.mock.ctrl.T.Helper()
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetUpdatedAt", reflect.TypeOf((*MockSessionRepository)(nil).SetUpdatedAt), updatedAt)
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetUpdatedAt", reflect.TypeOf((*MockSessionRepository)(nil).SetUpdatedAt), arg0)
return &MockSessionRepositorySetUpdatedAtCall{Call: call}
}
@@ -1005,44 +1081,6 @@ func (c *MockSessionRepositorySetUpdatedAtCall) DoAndReturn(f func(time.Time) da
return c
}
// SetUserAgent mocks base method.
func (m *MockSessionRepository) SetUserAgent(userAgent domain.SessionUserAgent) database.Change {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SetUserAgent", userAgent)
ret0, _ := ret[0].(database.Change)
return ret0
}
// SetUserAgent indicates an expected call of SetUserAgent.
func (mr *MockSessionRepositoryMockRecorder) SetUserAgent(userAgent any) *MockSessionRepositorySetUserAgentCall {
mr.mock.ctrl.T.Helper()
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetUserAgent", reflect.TypeOf((*MockSessionRepository)(nil).SetUserAgent), userAgent)
return &MockSessionRepositorySetUserAgentCall{Call: call}
}
// MockSessionRepositorySetUserAgentCall wrap *gomock.Call
type MockSessionRepositorySetUserAgentCall struct {
*gomock.Call
}
// Return rewrite *gomock.Call.Return
func (c *MockSessionRepositorySetUserAgentCall) Return(arg0 database.Change) *MockSessionRepositorySetUserAgentCall {
c.Call = c.Call.Return(arg0)
return c
}
// Do rewrite *gomock.Call.Do
func (c *MockSessionRepositorySetUserAgentCall) Do(f func(domain.SessionUserAgent) database.Change) *MockSessionRepositorySetUserAgentCall {
c.Call = c.Call.Do(f)
return c
}
// DoAndReturn rewrite *gomock.Call.DoAndReturn
func (c *MockSessionRepositorySetUserAgentCall) DoAndReturn(f func(domain.SessionUserAgent) database.Change) *MockSessionRepositorySetUserAgentCall {
c.Call = c.Call.DoAndReturn(f)
return c
}
// TokenColumn mocks base method.
func (m *MockSessionRepository) TokenColumn() database.Column {
m.ctrl.T.Helper()
@@ -1082,10 +1120,10 @@ func (c *MockSessionRepositoryTokenColumnCall) DoAndReturn(f func() database.Col
}
// Update mocks base method.
func (m *MockSessionRepository) Update(ctx context.Context, client database.QueryExecutor, condition database.Condition, changes ...database.Change) (int64, error) {
func (m *MockSessionRepository) Update(arg0 context.Context, arg1 database.QueryExecutor, arg2 database.Condition, arg3 ...database.Change) (int64, error) {
m.ctrl.T.Helper()
varargs := []any{ctx, client, condition}
for _, a := range changes {
varargs := []any{arg0, arg1, arg2}
for _, a := range arg3 {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "Update", varargs...)
@@ -1095,9 +1133,9 @@ func (m *MockSessionRepository) Update(ctx context.Context, client database.Quer
}
// Update indicates an expected call of Update.
func (mr *MockSessionRepositoryMockRecorder) Update(ctx, client, condition any, changes ...any) *MockSessionRepositoryUpdateCall {
func (mr *MockSessionRepositoryMockRecorder) Update(arg0, arg1, arg2 any, arg3 ...any) *MockSessionRepositoryUpdateCall {
mr.mock.ctrl.T.Helper()
varargs := append([]any{ctx, client, condition}, changes...)
varargs := append([]any{arg0, arg1, arg2}, arg3...)
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Update", reflect.TypeOf((*MockSessionRepository)(nil).Update), varargs...)
return &MockSessionRepositoryUpdateCall{Call: call}
}
@@ -1164,17 +1202,17 @@ func (c *MockSessionRepositoryUpdatedAtColumnCall) DoAndReturn(f func() database
}
// UpdatedAtCondition mocks base method.
func (m *MockSessionRepository) UpdatedAtCondition(op database.NumberOperation, updatedAt time.Time) database.Condition {
func (m *MockSessionRepository) UpdatedAtCondition(arg0 database.NumberOperation, arg1 time.Time) database.Condition {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "UpdatedAtCondition", op, updatedAt)
ret := m.ctrl.Call(m, "UpdatedAtCondition", arg0, arg1)
ret0, _ := ret[0].(database.Condition)
return ret0
}
// UpdatedAtCondition indicates an expected call of UpdatedAtCondition.
func (mr *MockSessionRepositoryMockRecorder) UpdatedAtCondition(op, updatedAt any) *MockSessionRepositoryUpdatedAtConditionCall {
func (mr *MockSessionRepositoryMockRecorder) UpdatedAtCondition(arg0, arg1 any) *MockSessionRepositoryUpdatedAtConditionCall {
mr.mock.ctrl.T.Helper()
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdatedAtCondition", reflect.TypeOf((*MockSessionRepository)(nil).UpdatedAtCondition), op, updatedAt)
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdatedAtCondition", reflect.TypeOf((*MockSessionRepository)(nil).UpdatedAtCondition), arg0, arg1)
return &MockSessionRepositoryUpdatedAtConditionCall{Call: call}
}
@@ -1201,94 +1239,18 @@ func (c *MockSessionRepositoryUpdatedAtConditionCall) DoAndReturn(f func(databas
return c
}
// UserAgentColumns mocks base method.
func (m *MockSessionRepository) UserAgentColumns() domain.SessionUserAgentColumns {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "UserAgentColumns")
ret0, _ := ret[0].(domain.SessionUserAgentColumns)
return ret0
}
// UserAgentColumns indicates an expected call of UserAgentColumns.
func (mr *MockSessionRepositoryMockRecorder) UserAgentColumns() *MockSessionRepositoryUserAgentColumnsCall {
mr.mock.ctrl.T.Helper()
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UserAgentColumns", reflect.TypeOf((*MockSessionRepository)(nil).UserAgentColumns))
return &MockSessionRepositoryUserAgentColumnsCall{Call: call}
}
// MockSessionRepositoryUserAgentColumnsCall wrap *gomock.Call
type MockSessionRepositoryUserAgentColumnsCall struct {
*gomock.Call
}
// Return rewrite *gomock.Call.Return
func (c *MockSessionRepositoryUserAgentColumnsCall) Return(arg0 domain.SessionUserAgentColumns) *MockSessionRepositoryUserAgentColumnsCall {
c.Call = c.Call.Return(arg0)
return c
}
// Do rewrite *gomock.Call.Do
func (c *MockSessionRepositoryUserAgentColumnsCall) Do(f func() domain.SessionUserAgentColumns) *MockSessionRepositoryUserAgentColumnsCall {
c.Call = c.Call.Do(f)
return c
}
// DoAndReturn rewrite *gomock.Call.DoAndReturn
func (c *MockSessionRepositoryUserAgentColumnsCall) DoAndReturn(f func() domain.SessionUserAgentColumns) *MockSessionRepositoryUserAgentColumnsCall {
c.Call = c.Call.DoAndReturn(f)
return c
}
// UserAgentConditions mocks base method.
func (m *MockSessionRepository) UserAgentConditions() domain.SessionUserAgentConditions {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "UserAgentConditions")
ret0, _ := ret[0].(domain.SessionUserAgentConditions)
return ret0
}
// UserAgentConditions indicates an expected call of UserAgentConditions.
func (mr *MockSessionRepositoryMockRecorder) UserAgentConditions() *MockSessionRepositoryUserAgentConditionsCall {
mr.mock.ctrl.T.Helper()
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UserAgentConditions", reflect.TypeOf((*MockSessionRepository)(nil).UserAgentConditions))
return &MockSessionRepositoryUserAgentConditionsCall{Call: call}
}
// MockSessionRepositoryUserAgentConditionsCall wrap *gomock.Call
type MockSessionRepositoryUserAgentConditionsCall struct {
*gomock.Call
}
// Return rewrite *gomock.Call.Return
func (c *MockSessionRepositoryUserAgentConditionsCall) Return(arg0 domain.SessionUserAgentConditions) *MockSessionRepositoryUserAgentConditionsCall {
c.Call = c.Call.Return(arg0)
return c
}
// Do rewrite *gomock.Call.Do
func (c *MockSessionRepositoryUserAgentConditionsCall) Do(f func() domain.SessionUserAgentConditions) *MockSessionRepositoryUserAgentConditionsCall {
c.Call = c.Call.Do(f)
return c
}
// DoAndReturn rewrite *gomock.Call.DoAndReturn
func (c *MockSessionRepositoryUserAgentConditionsCall) DoAndReturn(f func() domain.SessionUserAgentConditions) *MockSessionRepositoryUserAgentConditionsCall {
c.Call = c.Call.DoAndReturn(f)
return c
}
// UserAgentIDCondition mocks base method.
func (m *MockSessionRepository) UserAgentIDCondition(userAgentID string) database.Condition {
func (m *MockSessionRepository) UserAgentIDCondition(arg0 string) database.Condition {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "UserAgentIDCondition", userAgentID)
ret := m.ctrl.Call(m, "UserAgentIDCondition", arg0)
ret0, _ := ret[0].(database.Condition)
return ret0
}
// UserAgentIDCondition indicates an expected call of UserAgentIDCondition.
func (mr *MockSessionRepositoryMockRecorder) UserAgentIDCondition(userAgentID any) *MockSessionRepositoryUserAgentIDConditionCall {
func (mr *MockSessionRepositoryMockRecorder) UserAgentIDCondition(arg0 any) *MockSessionRepositoryUserAgentIDConditionCall {
mr.mock.ctrl.T.Helper()
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UserAgentIDCondition", reflect.TypeOf((*MockSessionRepository)(nil).UserAgentIDCondition), userAgentID)
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UserAgentIDCondition", reflect.TypeOf((*MockSessionRepository)(nil).UserAgentIDCondition), arg0)
return &MockSessionRepositoryUserAgentIDConditionCall{Call: call}
}
@@ -1354,17 +1316,17 @@ func (c *MockSessionRepositoryUserIDColumnCall) DoAndReturn(f func() database.Co
}
// UserIDCondition mocks base method.
func (m *MockSessionRepository) UserIDCondition(userID string) database.Condition {
func (m *MockSessionRepository) UserIDCondition(arg0 string) database.Condition {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "UserIDCondition", userID)
ret := m.ctrl.Call(m, "UserIDCondition", arg0)
ret0, _ := ret[0].(database.Condition)
return ret0
}
// UserIDCondition indicates an expected call of UserIDCondition.
func (mr *MockSessionRepositoryMockRecorder) UserIDCondition(userID any) *MockSessionRepositoryUserIDConditionCall {
func (mr *MockSessionRepositoryMockRecorder) UserIDCondition(arg0 any) *MockSessionRepositoryUserIDConditionCall {
mr.mock.ctrl.T.Helper()
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UserIDCondition", reflect.TypeOf((*MockSessionRepository)(nil).UserIDCondition), userID)
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UserIDCondition", reflect.TypeOf((*MockSessionRepository)(nil).UserIDCondition), arg0)
return &MockSessionRepositoryUserIDConditionCall{Call: call}
}
+27 -30
View File
@@ -8,18 +8,19 @@ import (
)
type Session struct {
InstanceID string `json:"instance_id,omitempty" db:"instance_id"`
ID string `json:"id,omitempty" db:"id"`
Token string `json:"token,omitempty" db:"token"`
Lifetime time.Duration `json:"lifetime,omitempty" db:"lifetime"`
Expiration time.Time `json:"expiration,omitzero" db:"expiration"`
UserID string `json:"user_id,omitempty" db:"user_id"`
CreatedAt time.Time `json:"created_at,omitzero" db:"created_at"`
UpdatedAt time.Time `json:"updated_at,omitzero" db:"updated_at"`
Factors SessionFactors `json:"factors,omitempty"`
Challenges SessionChallenges `json:"challenges,omitempty"`
Metadata []SessionMetadata `json:"metadata,omitempty"`
UserAgent *SessionUserAgent `json:"user_agent,omitempty"`
InstanceID string `json:"instanceId,omitempty" db:"instance_id"`
ID string `json:"id,omitempty" db:"id"`
TokenID string `json:"tokenId,omitempty" db:"token_id"`
Lifetime time.Duration `json:"lifetime,omitempty" db:"lifetime"`
Expiration time.Time `json:"expiration,omitzero" db:"expiration"`
UserID string `json:"userId,omitempty" db:"user_id"`
CreatorID string `json:"creatorId,omitempty" db:"creator_id"`
CreatedAt time.Time `json:"createdAt,omitzero" db:"created_at"`
UpdatedAt time.Time `json:"updatedAt,omitzero" db:"updated_at"`
Factors SessionFactors `json:"factors,omitempty"`
Challenges SessionChallenges `json:"challenges,omitempty"`
Metadata []*SessionMetadata `json:"metadata,omitempty"`
UserAgent *SessionUserAgent `json:"userAgent,omitempty"`
}
//go:generate mockgen -typed -package domainmock -destination ./mock/session.mock.go . SessionRepository
@@ -41,7 +42,7 @@ type SessionRepository interface {
// The condition must include at least the instanceID of the session to update.
Update(ctx context.Context, client database.QueryExecutor, condition database.Condition, changes ...database.Change) (int64, error)
// Delete removes sessions based on the given condition.
Delete(ctx context.Context, client database.QueryExecutor, condition database.Condition) error
Delete(ctx context.Context, client database.QueryExecutor, condition database.Condition) (int64, error)
}
// sessionColumns define all the columns of the session table.
@@ -50,8 +51,8 @@ type sessionColumns interface {
InstanceIDColumn() database.Column
// IDColumn returns the column for the id field.
IDColumn() database.Column
// TokenColumn returns the column for the token field.
TokenColumn() database.Column
// TokenIDColumn returns the column for the token id field.
TokenIDColumn() database.Column
// LifetimeColumn returns the column for the lifetime field.
LifetimeColumn() database.Column
// ExpirationColumn returns the column for the expiration field.
@@ -62,13 +63,6 @@ type sessionColumns interface {
CreatedAtColumn() database.Column
// UpdatedAtColumn returns the column for the updated at field.
UpdatedAtColumn() database.Column
// FactorColumns returns the columns for the factors fields.
FactorColumns() SessionFactorColumns
// MetadataColumns returns the columns for the metadata fields.
MetadataColumns() SessionMetadataColumns
// UserAgentColumns returns the columns for the user agent fields.
UserAgentColumns() SessionUserAgentColumns
}
// sessionConditions define all the conditions for the session table.
@@ -83,17 +77,22 @@ type sessionConditions interface {
UserAgentIDCondition(userAgentID string) database.Condition
// UserIDCondition returns an equal filter on the user id field.
UserIDCondition(userID string) database.Condition
// CreatorIDCondition returns an equal filter on the creator id field.
CreatorIDCondition(creatorID string) database.Condition
// ExpirationCondition returns a filter on the expiration field.
ExpirationCondition(op database.NumberOperation, expiration time.Time) database.Condition
// CreatedAtCondition returns a filter on the created at field.
CreatedAtCondition(op database.NumberOperation, createdAt time.Time) database.Condition
// UpdatedAtCondition returns a filter on the updated at field.
UpdatedAtCondition(op database.NumberOperation, updatedAt time.Time) database.Condition
// ExistsFactor returns a filter on the session's factors.
ExistsFactor(condition database.Condition) database.Condition
// FactorConditions returns the conditions for the factors fields.
FactorConditions() SessionFactorConditions
// ExistsMetadata returns a filter on the session's metadata.
ExistsMetadata(condition database.Condition) database.Condition
// MetadataConditions returns the conditions for the metadata fields.
MetadataConditions() SessionMetadataConditions
// UserAgentConditions returns the conditions for the user agent fields.
UserAgentConditions() SessionUserAgentConditions
}
type sessionChanges interface {
@@ -101,7 +100,7 @@ type sessionChanges interface {
// Only use this when reducing events,
// during regular updates the DB sets this column automatically.
SetUpdatedAt(updatedAt time.Time) database.Change
// SetToken sets the token field of the session.
// SetToken sets the token id field of the session.
SetToken(token string) database.Change
// SetLifetime sets the lifetime field of the session and will update the computed expiration field.
SetLifetime(lifetime time.Duration) database.Change
@@ -110,10 +109,8 @@ type sessionChanges interface {
SetChallenge(challenge SessionChallenge) database.Change
// SetFactor adds or updates the factor of the corresponding type.
SetFactor(factor SessionFactor) database.Change
// ClearFactor resets the factor of the corresponding type.
// ClearFactor resets the factor's verification.
ClearFactor(factor SessionFactorType) database.Change
// SetMetadata adds or updates the metadata of the session.
SetMetadata(metadata []SessionMetadata) database.Change
// SetUserAgent adds or updates the user agent of the session.
SetUserAgent(userAgent SessionUserAgent) database.Change
SetMetadata(metadata []*SessionMetadata) database.Change
}
+85 -78
View File
@@ -8,94 +8,112 @@ import (
"github.com/zitadel/zitadel/internal/domain"
)
type SessionFactorType int
//go:generate enumer -type=SessionFactorType -trimprefix SessionFactorType -transform snake -linecomment -sql
type SessionFactorType uint8
const (
SessionFactorTypeUnknown SessionFactorType = iota
SessionFactorTypeUser
SessionFactorTypePassword
SessionFactorTypePasskey // formerly known as WebAuthn
// SessionFactorTypePasskey was formerly known as WebAuthn
SessionFactorTypePasskey
SessionFactorTypeIdentityProviderIntent
// SessionFactorTypeTOTP used to be called OTP in some places
SessionFactorTypeTOTP
SessionFactorTypeOTPSMS
SessionFactorTypeOTPSMS // otp_sms
SessionFactorTypeOTPEmail
SessionFactorTypeRecoveryCode
)
type SessionFactor interface {
sessionFactorType() SessionFactorType
SessionFactorType() SessionFactorType
}
type SessionFactorUser struct {
UserID string
LastVerifiedAt time.Time
UserID string `json:"userId,omitempty" db:"user_id"`
LastVerifiedAt time.Time `json:"lastVerifiedAt,omitzero" db:"last_verified_at"`
}
// sessionFactorType implements [SessionFactor].
func (s *SessionFactorUser) sessionFactorType() SessionFactorType {
// SessionFactorType implements [SessionFactor].
func (s *SessionFactorUser) SessionFactorType() SessionFactorType {
return SessionFactorTypeUser
}
type SessionFactorPassword struct {
LastVerifiedAt time.Time
LastFailedAt time.Time
LastVerifiedAt time.Time `json:"lastVerifiedAt,omitzero" db:"last_verified_at"`
LastFailedAt time.Time `json:"lastFailedAt,omitzero" db:"last_failed_at"`
}
// sessionFactorType implements [SessionFactor].
func (s *SessionFactorPassword) sessionFactorType() SessionFactorType {
// SessionFactorType implements [SessionFactor].
func (s *SessionFactorPassword) SessionFactorType() SessionFactorType {
return SessionFactorTypePassword
}
type SessionFactorIdentityProviderIntent struct {
LastVerifiedAt time.Time
LastVerifiedAt time.Time `json:"lastVerifiedAt,omitzero" db:"last_verified_at"`
}
// sessionFactorType implements [SessionFactor].
func (s *SessionFactorIdentityProviderIntent) sessionFactorType() SessionFactorType {
// SessionFactorType implements [SessionFactor].
func (s *SessionFactorIdentityProviderIntent) SessionFactorType() SessionFactorType {
return SessionFactorTypeIdentityProviderIntent
}
type SessionFactorPasskey struct {
LastVerifiedAt time.Time
UserVerified bool
LastVerifiedAt time.Time `json:"lastVerifiedAt,omitzero" db:"last_verified_at"`
UserVerified bool `json:"userVerified,omitempty" db:"user_verified"`
}
// sessionFactorType implements [SessionFactor].
func (s *SessionFactorPasskey) sessionFactorType() SessionFactorType {
// SessionFactorType implements [SessionFactor].
func (s *SessionFactorPasskey) SessionFactorType() SessionFactorType {
return SessionFactorTypePasskey
}
type SessionFactorTOTP struct {
LastVerifiedAt time.Time
LastFailedAt time.Time
LastVerifiedAt time.Time `json:"lastVerifiedAt,omitzero" db:"last_verified_at"`
LastFailedAt time.Time `json:"lastFailedAt,omitzero" db:"last_failed_at"`
}
// sessionFactorType implements [SessionFactor].
func (s *SessionFactorTOTP) sessionFactorType() SessionFactorType {
// SessionFactorType implements [SessionFactor].
func (s *SessionFactorTOTP) SessionFactorType() SessionFactorType {
return SessionFactorTypeTOTP
}
type SessionFactorOTPSMS struct {
LastVerifiedAt time.Time
LastFailedAt time.Time
LastVerifiedAt time.Time `json:"lastVerifiedAt,omitzero" db:"last_verified_at"`
LastFailedAt time.Time `json:"lastFailedAt,omitzero" db:"last_failed_at"`
}
// sessionFactorType implements [SessionFactor].
func (s *SessionFactorOTPSMS) sessionFactorType() SessionFactorType {
// SessionFactorType implements [SessionFactor].
func (s *SessionFactorOTPSMS) SessionFactorType() SessionFactorType {
return SessionFactorTypeOTPSMS
}
type SessionFactorOTPEmail struct {
LastVerifiedAt time.Time
LastFailedAt time.Time
LastVerifiedAt time.Time `json:"lastVerifiedAt,omitzero" db:"last_verified_at"`
LastFailedAt time.Time `json:"lastFailedAt,omitzero" db:"last_failed_at"`
}
// sessionFactorType implements [SessionFactor].
func (s *SessionFactorOTPEmail) sessionFactorType() SessionFactorType {
// SessionFactorType implements [SessionFactor].
func (s *SessionFactorOTPEmail) SessionFactorType() SessionFactorType {
return SessionFactorTypeOTPEmail
}
type SessionFactorRecoveryCode struct {
LastVerifiedAt time.Time `json:"lastVerifiedAt,omitzero" db:"last_verified_at"`
LastFailedAt time.Time `json:"lastFailedAt,omitzero" db:"last_failed_at"`
}
// SessionFactorType implements [SessionFactor].
func (s *SessionFactorRecoveryCode) SessionFactorType() SessionFactorType {
return SessionFactorTypeRecoveryCode
}
type SessionFactors []SessionFactor
func (s *SessionFactors) AppendTo(factor SessionFactor) {
*s = append(*s, factor)
}
// GetUserFactor returns the user factor from the factors.
func (s SessionFactors) GetUserFactor() *SessionFactorUser {
factor, _ := GetFactor[*SessionFactorUser](s)
@@ -138,6 +156,12 @@ func (s SessionFactors) GetOTPEmailFactor() *SessionFactorOTPEmail {
return factor
}
// GetRecoveryCodeFactor returns the recovery code factor from the factors.
func (s SessionFactors) GetRecoveryCodeFactor() *SessionFactorRecoveryCode {
factor, _ := GetFactor[*SessionFactorRecoveryCode](s)
return factor
}
// GetFactor returns the factor of the given type from the factors.
func GetFactor[T SessionFactor](factors SessionFactors) (T, bool) {
var nilT T
@@ -150,52 +174,56 @@ func GetFactor[T SessionFactor](factors SessionFactors) (T, bool) {
}
type SessionChallenge interface {
sessionChallengeType() SessionFactorType
SessionChallengeType() SessionFactorType
}
type SessionChallengePasskey struct {
LastChallengedAt time.Time
Challenge string
AllowedCredentialIDs [][]byte
UserVerification domain.UserVerificationRequirement
RPID string
LastChallengedAt time.Time `json:"lastChallengedAt,omitzero" db:"last_challenged_at"`
Challenge string `json:"challenge,omitempty" db:"challenge"`
AllowedCredentialIDs [][]byte `json:"allowedCredentialIDs,omitempty" db:"allowed_credential_ids"`
UserVerification domain.UserVerificationRequirement `json:"userVerification,omitempty" db:"user_verification"`
RPID string `json:"rpId,omitempty" db:"rp_id"`
}
// sessionChallengeType implements [SessionChallenge].
func (s *SessionChallengePasskey) sessionChallengeType() SessionFactorType {
// SessionChallengeType implements [SessionChallenge].
func (s *SessionChallengePasskey) SessionChallengeType() SessionFactorType {
return SessionFactorTypePasskey
}
type SessionChallengeOTPSMS struct {
LastChallengedAt time.Time
Code *crypto.CryptoValue
Expiry time.Duration
CodeReturned bool
GeneratorID string
TriggeredAtOrigin string
LastChallengedAt time.Time `json:"lastChallengedAt,omitzero" db:"last_challenged_at"`
Code *crypto.CryptoValue `json:"code,omitempty" db:"code"`
Expiry time.Duration `json:"expiry,omitzero" db:"expiry"`
CodeReturned bool `json:"codeReturned,omitempty" db:"code_returned"`
GeneratorID string `json:"generatorId,omitempty" db:"generator_id"`
TriggeredAtOrigin string `json:"triggeredAtOrigin,omitempty" db:"triggered_at_origin"`
}
// sessionChallengeType implements [SessionChallenge].
func (s *SessionChallengeOTPSMS) sessionChallengeType() SessionFactorType {
// SessionChallengeType implements [SessionChallenge].
func (s *SessionChallengeOTPSMS) SessionChallengeType() SessionFactorType {
return SessionFactorTypeOTPSMS
}
type SessionChallengeOTPEmail struct {
LastChallengedAt time.Time
Code *crypto.CryptoValue
Expiry time.Duration
CodeReturned bool
URLTmpl string
TriggeredAtOrigin string
LastChallengedAt time.Time `json:"lastChallengedAt,omitzero" db:"last_challenged_at"`
Code *crypto.CryptoValue `json:"code,omitempty" db:"code"`
Expiry time.Duration `json:"expiry,omitzero" db:"expiry"`
CodeReturned bool `json:"codeReturned,omitempty" db:"code_returned"`
URLTemplate string `json:"urlTemplate,omitempty" db:"url_template"`
TriggeredAtOrigin string `json:"triggeredAtOrigin,omitempty" db:"triggered_at_origin"`
}
// sessionChallengeType implements [SessionChallenge].
func (s *SessionChallengeOTPEmail) sessionChallengeType() SessionFactorType {
// SessionChallengeType implements [SessionChallenge].
func (s *SessionChallengeOTPEmail) SessionChallengeType() SessionFactorType {
return SessionFactorTypeOTPEmail
}
type SessionChallenges []SessionChallenge
func (s *SessionChallenges) AppendTo(challenge SessionChallenge) {
*s = append(*s, challenge)
}
// GetPasskeyChallenge returns the passkey challenge from the challenges.
func (s SessionChallenges) GetPasskeyChallenge() *SessionChallengePasskey {
challenge, _ := GetChallenge[*SessionChallengePasskey](s)
@@ -225,30 +253,9 @@ func GetChallenge[T SessionChallenge](challenges SessionChallenges) (T, bool) {
return nilT, false
}
type SessionFactorColumns interface {
// InstanceIDColumn returns the column for the instance id field.
InstanceIDColumn() database.Column
// SessionIDColumn returns the column for the session id field.
SessionIDColumn() database.Column
// FactorTypeColumn returns the column for the factor type field.
FactorTypeColumn() database.Column
// LastChallengedAtColumn returns the column for the last challenged at field.
LastChallengedAtColumn() database.Column
// LastFailedAtColumn returns the column for the last failed at field.
LastFailedAtColumn() database.Column
// LastVerifiedAtColumn returns the column for the last verified at field.
LastVerifiedAtColumn() database.Column
}
type SessionFactorConditions interface {
// PrimaryKeyCondition returns a filter on the primary key fields.
PrimaryKeyCondition(instanceID, sessionID string, factorType SessionFactorType) database.Condition
// InstanceIDCondition returns an equal filter on the instance id field.
InstanceIDCondition(instanceID string) database.Condition
// SessionIDCondition returns an equal filter on the session id field.
SessionIDCondition(sessionID string) database.Condition
// FactorTypeCondition returns an equal filter on the factor type field.
FactorTypeCondition(factorType SessionFactorType) database.Condition
// FactorLastVerifiedBeforeCondition returns a filter on the factor last verified field before the given time.
FactorLastVerifiedBeforeCondition(lastVerifiedAt time.Time) database.Condition
// LastVerifiedBeforeCondition returns a filter on the factor last verified field before the given time.
LastVerifiedBeforeCondition(lastVerifiedAt time.Time) database.Condition
}
+1 -2
View File
@@ -8,11 +8,10 @@ import (
)
type SessionUserAgent struct {
InstanceID string `json:"instanceId,omitempty" db:"instance_id"`
FingerprintID *string `json:"fingerprintId,omitempty" db:"fingerprint_id"`
Description *string `json:"description,omitempty" db:"description"`
IP net.IP `json:"ip,omitempty" db:"ip"`
Header http.Header `json:"header,omitempty" db:"headers"`
Header http.Header `json:"headers,omitempty" db:"headers"`
}
type SessionUserAgentColumns interface {
@@ -0,0 +1,137 @@
// Code generated by "enumer -type=SessionFactorType -trimprefix SessionFactorType -transform snake -linecomment -sql"; DO NOT EDIT.
package domain
import (
"database/sql/driver"
"fmt"
"strings"
)
const _SessionFactorTypeName = "unknownuserpasswordpasskeyidentity_provider_intenttotpotp_smsotp_emailrecovery_code"
var _SessionFactorTypeIndex = [...]uint8{0, 7, 11, 19, 26, 50, 54, 61, 70, 83}
const _SessionFactorTypeLowerName = "unknownuserpasswordpasskeyidentity_provider_intenttotpotp_smsotp_emailrecovery_code"
func (i SessionFactorType) String() string {
if i >= SessionFactorType(len(_SessionFactorTypeIndex)-1) {
return fmt.Sprintf("SessionFactorType(%d)", i)
}
return _SessionFactorTypeName[_SessionFactorTypeIndex[i]:_SessionFactorTypeIndex[i+1]]
}
// An "invalid array index" compiler error signifies that the constant values have changed.
// Re-run the stringer command to generate them again.
func _SessionFactorTypeNoOp() {
var x [1]struct{}
_ = x[SessionFactorTypeUnknown-(0)]
_ = x[SessionFactorTypeUser-(1)]
_ = x[SessionFactorTypePassword-(2)]
_ = x[SessionFactorTypePasskey-(3)]
_ = x[SessionFactorTypeIdentityProviderIntent-(4)]
_ = x[SessionFactorTypeTOTP-(5)]
_ = x[SessionFactorTypeOTPSMS-(6)]
_ = x[SessionFactorTypeOTPEmail-(7)]
_ = x[SessionFactorTypeRecoveryCode-(8)]
}
var _SessionFactorTypeValues = []SessionFactorType{SessionFactorTypeUnknown, SessionFactorTypeUser, SessionFactorTypePassword, SessionFactorTypePasskey, SessionFactorTypeIdentityProviderIntent, SessionFactorTypeTOTP, SessionFactorTypeOTPSMS, SessionFactorTypeOTPEmail, SessionFactorTypeRecoveryCode}
var _SessionFactorTypeNameToValueMap = map[string]SessionFactorType{
_SessionFactorTypeName[0:7]: SessionFactorTypeUnknown,
_SessionFactorTypeLowerName[0:7]: SessionFactorTypeUnknown,
_SessionFactorTypeName[7:11]: SessionFactorTypeUser,
_SessionFactorTypeLowerName[7:11]: SessionFactorTypeUser,
_SessionFactorTypeName[11:19]: SessionFactorTypePassword,
_SessionFactorTypeLowerName[11:19]: SessionFactorTypePassword,
_SessionFactorTypeName[19:26]: SessionFactorTypePasskey,
_SessionFactorTypeLowerName[19:26]: SessionFactorTypePasskey,
_SessionFactorTypeName[26:50]: SessionFactorTypeIdentityProviderIntent,
_SessionFactorTypeLowerName[26:50]: SessionFactorTypeIdentityProviderIntent,
_SessionFactorTypeName[50:54]: SessionFactorTypeTOTP,
_SessionFactorTypeLowerName[50:54]: SessionFactorTypeTOTP,
_SessionFactorTypeName[54:61]: SessionFactorTypeOTPSMS,
_SessionFactorTypeLowerName[54:61]: SessionFactorTypeOTPSMS,
_SessionFactorTypeName[61:70]: SessionFactorTypeOTPEmail,
_SessionFactorTypeLowerName[61:70]: SessionFactorTypeOTPEmail,
_SessionFactorTypeName[70:83]: SessionFactorTypeRecoveryCode,
_SessionFactorTypeLowerName[70:83]: SessionFactorTypeRecoveryCode,
}
var _SessionFactorTypeNames = []string{
_SessionFactorTypeName[0:7],
_SessionFactorTypeName[7:11],
_SessionFactorTypeName[11:19],
_SessionFactorTypeName[19:26],
_SessionFactorTypeName[26:50],
_SessionFactorTypeName[50:54],
_SessionFactorTypeName[54:61],
_SessionFactorTypeName[61:70],
_SessionFactorTypeName[70:83],
}
// SessionFactorTypeString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func SessionFactorTypeString(s string) (SessionFactorType, error) {
if val, ok := _SessionFactorTypeNameToValueMap[s]; ok {
return val, nil
}
if val, ok := _SessionFactorTypeNameToValueMap[strings.ToLower(s)]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to SessionFactorType values", s)
}
// SessionFactorTypeValues returns all values of the enum
func SessionFactorTypeValues() []SessionFactorType {
return _SessionFactorTypeValues
}
// SessionFactorTypeStrings returns a slice of all String values of the enum
func SessionFactorTypeStrings() []string {
strs := make([]string, len(_SessionFactorTypeNames))
copy(strs, _SessionFactorTypeNames)
return strs
}
// IsASessionFactorType returns "true" if the value is listed in the enum definition. "false" otherwise
func (i SessionFactorType) IsASessionFactorType() bool {
for _, v := range _SessionFactorTypeValues {
if i == v {
return true
}
}
return false
}
func (i SessionFactorType) Value() (driver.Value, error) {
return i.String(), nil
}
func (i *SessionFactorType) Scan(value interface{}) error {
if value == nil {
return nil
}
var str string
switch v := value.(type) {
case []byte:
str = string(v)
case string:
str = v
case fmt.Stringer:
str = v.String()
default:
return fmt.Errorf("invalid value of SessionFactorType: %[1]T(%[1]v)", value)
}
val, err := SessionFactorTypeString(str)
if err != nil {
return err
}
*i = val
return nil
}