-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #526 from tidepool-org/tk-async-deletes
[BACK-1737] Delete blobs, data, data sources, restricted tokens and provider sessions when users are deleted
- Loading branch information
Showing
641 changed files
with
80,978 additions
and
1,188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package events | ||
|
||
import ( | ||
"context" | ||
|
||
ev "github.com/tidepool-org/go-common/events" | ||
|
||
"github.com/tidepool-org/platform/auth" | ||
"github.com/tidepool-org/platform/errors" | ||
"github.com/tidepool-org/platform/log" | ||
) | ||
|
||
type userDeletionEventsHandler struct { | ||
ev.NoopUserEventsHandler | ||
|
||
ctx context.Context | ||
client auth.Client | ||
} | ||
|
||
func NewUserDataDeletionHandler(ctx context.Context, client auth.Client) ev.EventHandler { | ||
return ev.NewUserEventsHandler(&userDeletionEventsHandler{ | ||
ctx: ctx, | ||
client: client, | ||
}) | ||
} | ||
|
||
func (u *userDeletionEventsHandler) HandleDeleteUserEvent(payload ev.DeleteUserEvent) error { | ||
var errs []error | ||
logger := log.LoggerFromContext(u.ctx).WithField("userId", payload.UserID) | ||
|
||
logger.Infof("Deleting restricted tokens for user") | ||
if err := u.client.DeleteAllRestrictedTokens(u.ctx, payload.UserID); err != nil { | ||
errs = append(errs, err) | ||
logger.WithError(err).Error("unable to delete restricted tokens for user") | ||
} | ||
|
||
logger.Infof("Deleting provider sessions for user") | ||
if err := u.client.DeleteAllProviderSessions(u.ctx, payload.UserID); err != nil { | ||
errs = append(errs, err) | ||
logger.WithError(err).Error("unable to delete provider sessions for user") | ||
} | ||
|
||
if len(errs) != 0 { | ||
return errors.New("Unable to delete auth data for user") | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package events | ||
|
||
import ( | ||
"context" | ||
|
||
ev "github.com/tidepool-org/go-common/events" | ||
|
||
"github.com/tidepool-org/platform/blob" | ||
"github.com/tidepool-org/platform/log" | ||
) | ||
|
||
type userDeletionEventsHandler struct { | ||
ev.NoopUserEventsHandler | ||
|
||
ctx context.Context | ||
blobClient blob.Client | ||
} | ||
|
||
func NewUserDataDeletionHandler(ctx context.Context, blobClient blob.Client) ev.EventHandler { | ||
return ev.NewUserEventsHandler(&userDeletionEventsHandler{ | ||
ctx: ctx, | ||
blobClient: blobClient, | ||
}) | ||
} | ||
|
||
func (u *userDeletionEventsHandler) HandleDeleteUserEvent(payload ev.DeleteUserEvent) error { | ||
log.LoggerFromContext(u.ctx).WithField("userId", payload.UserID).Infof("Deleting blobs for user") | ||
return u.blobClient.DeleteAll(u.ctx, payload.UserID) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.