Fixes MM-50733 (#22784)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
0af69b3411
Коммит
7325c38c39
@@ -5555,6 +5555,24 @@ func (s *OpenTracingLayerOAuthStore) RemoveAuthDataByClientId(clientId string, u
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerOAuthStore) RemoveAuthDataByUserId(userId string) error {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "OAuthStore.RemoveAuthDataByUserId")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
s.Root.Store.SetContext(origCtx)
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
err := s.OAuthStore.RemoveAuthDataByUserId(userId)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerOAuthStore) SaveAccessData(accessData *model.AccessData) (*model.AccessData, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "OAuthStore.SaveAccessData")
|
||||
|
||||
@@ -6298,6 +6298,27 @@ func (s *RetryLayerOAuthStore) RemoveAuthDataByClientId(clientId string, userId
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerOAuthStore) RemoveAuthDataByUserId(userId string) error {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
err := s.OAuthStore.RemoveAuthDataByUserId(userId)
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
if !isRepeatableError(err) {
|
||||
return err
|
||||
}
|
||||
tries++
|
||||
if tries >= 3 {
|
||||
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
|
||||
return err
|
||||
}
|
||||
timepkg.Sleep(100 * timepkg.Millisecond)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerOAuthStore) SaveAccessData(accessData *model.AccessData) (*model.AccessData, error) {
|
||||
|
||||
tries := 0
|
||||
|
||||
@@ -269,6 +269,14 @@ func (as SqlOAuthStore) RemoveAuthDataByClientId(clientId string, userId string)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (as SqlOAuthStore) RemoveAuthDataByUserId(userId string) error {
|
||||
_, err := as.GetMasterX().Exec("DELETE FROM OAuthAuthData WHERE UserId = ?", userId)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to delete AuthData with userId=%s", userId)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (as SqlOAuthStore) PermanentDeleteAuthDataByUser(userId string) error {
|
||||
_, err := as.GetMasterX().Exec("DELETE FROM OAuthAccessData WHERE UserId = ?", userId)
|
||||
if err != nil {
|
||||
|
||||
@@ -564,6 +564,7 @@ type OAuthStore interface {
|
||||
GetAuthData(code string) (*model.AuthData, error)
|
||||
RemoveAuthData(code string) error
|
||||
RemoveAuthDataByClientId(clientId string, userId string) error
|
||||
RemoveAuthDataByUserId(userId string) error
|
||||
PermanentDeleteAuthDataByUser(userID string) error
|
||||
SaveAccessData(accessData *model.AccessData) (*model.AccessData, error)
|
||||
UpdateAccessData(accessData *model.AccessData) (*model.AccessData, error)
|
||||
|
||||
@@ -305,6 +305,20 @@ func (_m *OAuthStore) RemoveAuthDataByClientId(clientId string, userId string) e
|
||||
return r0
|
||||
}
|
||||
|
||||
// RemoveAuthDataByUserId provides a mock function with given fields: userId
|
||||
func (_m *OAuthStore) RemoveAuthDataByUserId(userId string) error {
|
||||
ret := _m.Called(userId)
|
||||
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(string) error); ok {
|
||||
r0 = rf(userId)
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// SaveAccessData provides a mock function with given fields: accessData
|
||||
func (_m *OAuthStore) SaveAccessData(accessData *model.AccessData) (*model.AccessData, error) {
|
||||
ret := _m.Called(accessData)
|
||||
|
||||
@@ -5036,6 +5036,22 @@ func (s *TimerLayerOAuthStore) RemoveAuthDataByClientId(clientId string, userId
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *TimerLayerOAuthStore) RemoveAuthDataByUserId(userId string) error {
|
||||
start := time.Now()
|
||||
|
||||
err := s.OAuthStore.RemoveAuthDataByUserId(userId)
|
||||
|
||||
elapsed := float64(time.Since(start)) / float64(time.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
success := "false"
|
||||
if err == nil {
|
||||
success = "true"
|
||||
}
|
||||
s.Root.Metrics.ObserveStoreMethodDuration("OAuthStore.RemoveAuthDataByUserId", success, elapsed)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *TimerLayerOAuthStore) SaveAccessData(accessData *model.AccessData) (*model.AccessData, error) {
|
||||
start := time.Now()
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user