Этот коммит содержится в:
Rohitesh Gupta
2023-04-06 01:28:21 +05:30
коммит произвёл GitHub
родитель 0af69b3411
Коммит 7325c38c39
9 изменённых файлов: 130 добавлений и 0 удалений

Просмотреть файл

@@ -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()