@@ -38,7 +38,7 @@ func (r *BridgeRunner) acquireNextBridge(ctx context.Context) (*coredata.SCIMBri
|
||||
|
||||
err := r.pg.WithTx(
|
||||
ctx,
|
||||
func(tx pg.Conn) error {
|
||||
func(ctx context.Context, tx pg.Tx) error {
|
||||
bridge = &coredata.SCIMBridge{}
|
||||
if err := bridge.LoadNextForSyncSkipLocked(ctx, tx, r.cfg.StaleSyncThreshold); err != nil {
|
||||
return err
|
||||
@@ -70,9 +70,9 @@ func (r *BridgeRunner) transitionToSuccess(
|
||||
connector *coredata.Connector,
|
||||
logger *log.Logger,
|
||||
) error {
|
||||
return r.pg.WithConn(
|
||||
return r.pg.WithTx(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
func(ctx context.Context, tx pg.Tx) error {
|
||||
now := time.Now()
|
||||
nextSync := now.Add(r.cfg.Interval)
|
||||
|
||||
@@ -84,7 +84,7 @@ func (r *BridgeRunner) transitionToSuccess(
|
||||
bridge.TotalSyncCount++
|
||||
bridge.UpdatedAt = now
|
||||
|
||||
if err := bridge.Update(ctx, conn, scope); err != nil {
|
||||
if err := bridge.Update(ctx, tx, scope); err != nil {
|
||||
logger.ErrorCtx(
|
||||
ctx,
|
||||
"cannot update bridge after successful sync",
|
||||
@@ -95,7 +95,7 @@ func (r *BridgeRunner) transitionToSuccess(
|
||||
|
||||
if connector != nil {
|
||||
connector.UpdatedAt = now
|
||||
if err := connector.Update(ctx, conn, scope, r.encryptionKey); err != nil {
|
||||
if err := connector.Update(ctx, tx, scope, r.encryptionKey); err != nil {
|
||||
logger.WarnCtx(
|
||||
ctx,
|
||||
"cannot persist refreshed OAuth2 token",
|
||||
@@ -129,9 +129,9 @@ func (r *BridgeRunner) transitionToFailed(
|
||||
duration time.Duration,
|
||||
logger *log.Logger,
|
||||
) error {
|
||||
return r.pg.WithConn(
|
||||
return r.pg.WithTx(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
func(ctx context.Context, tx pg.Tx) error {
|
||||
now := time.Now()
|
||||
|
||||
bridge.ConsecutiveFailures++
|
||||
@@ -171,7 +171,7 @@ func (r *BridgeRunner) transitionToFailed(
|
||||
)
|
||||
}
|
||||
|
||||
if err := bridge.Update(ctx, conn, scope); err != nil {
|
||||
if err := bridge.Update(ctx, tx, scope); err != nil {
|
||||
logger.ErrorCtx(
|
||||
ctx,
|
||||
"cannot update bridge after failed sync",
|
||||
|
||||
@@ -38,11 +38,11 @@ func (r *BridgeRunner) executeSync(
|
||||
) (stats SyncStats, duration time.Duration, connector *coredata.Connector, err error) {
|
||||
start := time.Now()
|
||||
|
||||
err = r.pg.WithConn(
|
||||
err = r.pg.WithTx(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
func(ctx context.Context, tx pg.Tx) error {
|
||||
var syncErr error
|
||||
stats, connector, syncErr = r.doSync(ctx, conn, bridge, scope, logger)
|
||||
stats, connector, syncErr = r.doSync(ctx, tx, bridge, scope, logger)
|
||||
return syncErr
|
||||
},
|
||||
)
|
||||
@@ -53,7 +53,7 @@ func (r *BridgeRunner) executeSync(
|
||||
|
||||
func (r *BridgeRunner) doSync(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
tx pg.Tx,
|
||||
scimBridge *coredata.SCIMBridge,
|
||||
scope coredata.Scoper,
|
||||
logger *log.Logger,
|
||||
@@ -63,7 +63,7 @@ func (r *BridgeRunner) doSync(
|
||||
}
|
||||
|
||||
dbConnector := &coredata.Connector{}
|
||||
if err := dbConnector.LoadByID(ctx, conn, scope, *scimBridge.ConnectorID, r.encryptionKey); err != nil {
|
||||
if err := dbConnector.LoadByID(ctx, tx, scope, *scimBridge.ConnectorID, r.encryptionKey); err != nil {
|
||||
return SyncStats{}, nil, fmt.Errorf("cannot load connector: %w", err)
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ func (r *BridgeRunner) doSync(
|
||||
}
|
||||
|
||||
var scimConfig coredata.SCIMConfiguration
|
||||
if err := scimConfig.LoadByID(ctx, conn, scope, scimBridge.ScimConfigurationID); err != nil {
|
||||
if err := scimConfig.LoadByID(ctx, tx, scope, scimBridge.ScimConfigurationID); err != nil {
|
||||
return SyncStats{}, nil, fmt.Errorf("cannot load SCIM configuration: %w", err)
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ func (r *BridgeRunner) doSync(
|
||||
|
||||
scimConfig.HashedToken = HashToken(token)
|
||||
scimConfig.UpdatedAt = time.Now()
|
||||
if err := scimConfig.Update(ctx, conn, scope); err != nil {
|
||||
if err := scimConfig.Update(ctx, tx, scope); err != nil {
|
||||
return SyncStats{}, nil, fmt.Errorf("cannot update SCIM configuration token: %w", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ func (s *Service) ValidateToken(ctx context.Context, token string) (*coredata.SC
|
||||
|
||||
err := s.pg.WithConn(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
func(ctx context.Context, conn pg.Querier) error {
|
||||
err := config.LoadByHashedToken(ctx, conn, hashedToken)
|
||||
if err != nil {
|
||||
if err == coredata.ErrResourceNotFound {
|
||||
@@ -160,7 +160,7 @@ func (s *Service) CreateUser(
|
||||
|
||||
scope := coredata.NewScopeFromObjectID(config.OrganizationID)
|
||||
|
||||
err = s.pg.WithTx(ctx, func(tx pg.Conn) error {
|
||||
err = s.pg.WithTx(ctx, func(ctx context.Context, tx pg.Tx) error {
|
||||
identity := &coredata.Identity{}
|
||||
if err := identity.LoadByEmail(ctx, tx, emailAddr); err != nil {
|
||||
if errors.Is(err, coredata.ErrResourceNotFound) {
|
||||
@@ -355,7 +355,7 @@ func (s *Service) GetUser(
|
||||
|
||||
err := s.pg.WithConn(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
func(ctx context.Context, conn pg.Querier) error {
|
||||
profile = &coredata.MembershipProfile{}
|
||||
if err := profile.LoadByID(ctx, conn, scope, profileID); err != nil {
|
||||
if err == coredata.ErrResourceNotFound {
|
||||
@@ -405,7 +405,7 @@ func (s *Service) ListUsers(
|
||||
|
||||
err = s.pg.WithConn(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
func(ctx context.Context, conn pg.Querier) error {
|
||||
var err error
|
||||
totalCount, err = profiles.CountByOrganizationID(ctx, conn, scope, config.OrganizationID, filter)
|
||||
if err != nil {
|
||||
@@ -486,7 +486,7 @@ func (s *Service) updateUser(
|
||||
|
||||
err := s.pg.WithTx(
|
||||
ctx,
|
||||
func(tx pg.Conn) error {
|
||||
func(ctx context.Context, tx pg.Tx) error {
|
||||
profile = &coredata.MembershipProfile{}
|
||||
if err := profile.LoadByID(ctx, tx, scope, profileID); err != nil {
|
||||
if errors.Is(err, coredata.ErrResourceNotFound) {
|
||||
@@ -772,7 +772,7 @@ func (s *Service) DeleteUser(
|
||||
|
||||
return s.pg.WithTx(
|
||||
ctx,
|
||||
func(tx pg.Conn) error {
|
||||
func(ctx context.Context, tx pg.Tx) error {
|
||||
profile := &coredata.MembershipProfile{}
|
||||
if err := profile.LoadByID(ctx, tx, scope, profileID); err != nil {
|
||||
if errors.Is(err, coredata.ErrResourceNotFound) {
|
||||
@@ -837,10 +837,10 @@ func (s *Service) LogEvent(
|
||||
|
||||
event := s.createEvent(config, method, path, userName, ipAddress, statusCode, errorMessage)
|
||||
|
||||
err := s.pg.WithConn(
|
||||
err := s.pg.WithTx(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
err := event.Insert(ctx, conn, scope)
|
||||
func(ctx context.Context, tx pg.Tx) error {
|
||||
err := event.Insert(ctx, tx, scope)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot insert SCIM event: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user