feat(GODT-2801): Identity State Cloning & Auth Check

This patch moves the `user.User.CheckAuth` function into the `State`
type as it contains all the necessary information to perform this check.

A couple of more interfaces are added to abstract the retrieval of the
Bridge and the User's key passwords, as well as telemetry reports.

Finally, adds `State.OnAddressEvents` which other services should use to
update the state.
This commit is contained in:
Leander Beernaert
2023-07-24 17:00:57 +02:00
parent bdbf1bdd76
commit 7be1a8ae8a
5 changed files with 119 additions and 25 deletions

View File

@ -51,33 +51,25 @@ type Service struct {
}
func NewService(
ctx context.Context,
service userevents.Subscribable,
user proton.User,
eventPublisher events.EventPublisher,
provider IdentityProvider,
) (*Service, error) {
addresses, err := provider.GetAddresses(ctx)
if err != nil {
return nil, fmt.Errorf("failed to get addresses: %w", err)
}
subscriberName := fmt.Sprintf("identity-%v", user.ID)
state *State,
) *Service {
subscriberName := fmt.Sprintf("identity-%v", state.User.ID)
return &Service{
eventService: service,
identity: NewState(user, addresses, provider),
identity: *state,
eventPublisher: eventPublisher,
log: logrus.WithFields(logrus.Fields{
"service": "user-identity",
"user": user.ID,
"user": state.User.ID,
}),
userSubscriber: userevents.NewUserSubscriber(subscriberName),
refreshSubscriber: userevents.NewRefreshSubscriber(subscriberName),
addressSubscriber: userevents.NewAddressSubscriber(subscriberName),
usedSpaceSubscriber: userevents.NewUserUsedSpaceSubscriber(subscriberName),
}, nil
}
}
func (s *Service) Start(group *async.Group) {