Skip to content
This repository was archived by the owner on Jun 21, 2022. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ required = [

[[constraint]]
name = "github.com/percona/pmm"
branch = "PMM-2.0"
branch = "SAAS-174-password-reset"

[[constraint]]
name = "github.com/percona-platform/saas"
branch = "main"
branch = "SAAS-174-password-reset"

# to prevent unexpected downgrades; see https://github.com/percona/exporter_shared/releases/tag/v0.6.0
[[constraint]]
Expand Down
16 changes: 16 additions & 0 deletions services/platform/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,22 @@ func (s *Service) refreshSession(ctx context.Context) error {
return nil
}

// ResetPassword initiates password reset procedure for user with given email.
func (s *Service) ResetPassword(ctx context.Context, email string) error {
cc, err := dial(ctx, s.host)
if err != nil {
return errors.Wrap(err, "failed establish connection with Percona")
}
defer cc.Close() //nolint:errcheck

_, err = api.NewAuthAPIClient(cc).ResetPassword(ctx, &api.ResetPasswordRequest{Email: email})
if err != nil {
return errors.Wrap(err, "failed to reset password")
}

return nil
}

func dial(ctx context.Context, fullHost string) (*grpc.ClientConn, error) {
host, _, err := net.SplitHostPort(fullHost)
if err != nil {
Expand Down
11 changes: 11 additions & 0 deletions services/platform/platform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@ func TestPlatformService(t *testing.T) {
err = s.refreshSession(context.Background())
assert.NoError(t, err)
})

t.Run("ResetPassword", func(t *testing.T) {
login := gofakeit.Email()
password := gofakeit.Password(true, true, true, false, false, 14)

err := s.SignUp(context.Background(), login, password)
require.NoError(t, err)

err = s.ResetPassword(context.Background(), login)
assert.NoError(t, err)
})
}

func init() { //nolint:gochecknoinits
Expand Down
1 change: 1 addition & 0 deletions services/server/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,5 @@ type telemetryService interface {
type platformService interface {
SignUp(ctx context.Context, email, password string) error
SignIn(ctx context.Context, email, password string) error
ResetPassword(ctx context.Context, email string) error
}
14 changes: 14 additions & 0 deletions services/server/mock_platform_service_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions services/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,17 @@ func (s *Server) PlatformSignIn(ctx context.Context, req *serverpb.PlatformSignI
return &serverpb.PlatformSignInResponse{}, nil
}

// PlatformResetPassword initiates Percona Platform user's password reset procedure.
func (s *Server) PlatformResetPassword(ctx context.Context, req *serverpb.PlatformResetPasswordRequest) (*serverpb.PlatformResetPasswordResponse, error) {
nCtx, cancel := context.WithTimeout(ctx, platformAPITimeout)
defer cancel()
if err := s.platformService.ResetPassword(nCtx, req.Email); err != nil {
return nil, err
}

return &serverpb.PlatformResetPasswordResponse{}, nil
}

// check interfaces
var (
_ serverpb.ServerServer = (*Server)(nil)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading