Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scaffold identity server #371

Merged
merged 8 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 1 addition & 1 deletion dev/up
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ if ! which golangci-lint &>/dev/null; then brew install golangci-lint; fi
if ! which shellcheck &>/dev/null; then brew install shellcheck; fi
if ! which protoc &>/dev/null; then brew install protobuf; fi
if ! which protoc-gen-go &>/dev/null; then go install google.golang.org/protobuf/cmd/protoc-gen-go@latest; fi
if ! which mockgen &>/dev/null; then go install go.uber.org/mock/mockgen@latest; fi
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one was a pain to find, but tests were failing until I did this.

Basically, it's entirely possible you have a different version of mockgen installed on your system (in fact, you're guaranteed to have it if you have developed against xmtp-node-go in the past). That would be github.com/golang/mock/mockgen instead of this uber one.

The reason for the use of the uber one seems to be the .Satisfied property, which lets you check on an interval if all of the expected API calls were performed on the mock. We're using it in tests like this:

require.Eventually(t, ctrl.Satisfied, 5*time.Second, 100*time.Millisecond)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch

go install go.uber.org/mock/mockgen@latest
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there no way to tell if you have the correct mockgen and only run this if you have the wrong one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I found a hack to only run this if the version is not 0.4.0. Basically we can pin the uber mockgen on the current version of v0.4.0 and update as needed. Should be good indefinitely because it is running behind the golang one, which is on v1.6.0

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

if ! which protolint &>/dev/null; then go install github.com/yoheimuta/protolint/cmd/protolint@latest; fi

dev/generate
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ require (
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/glog v1.0.0 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/mock v1.6.0
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/gopacket v1.1.19 // indirect
Expand Down
16 changes: 15 additions & 1 deletion pkg/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
swgui "github.com/swaggest/swgui/v3"
wakupb "github.com/waku-org/go-waku/waku/v2/protocol/pb"
wakurelay "github.com/waku-org/go-waku/waku/v2/protocol/relay"
identityv1pb "github.com/xmtp/xmtp-node-go/pkg/proto/identity/api/v1"
proto "github.com/xmtp/xmtp-node-go/pkg/proto/message_api/v1"
mlsv1pb "github.com/xmtp/xmtp-node-go/pkg/proto/mls/api/v1"
messagev1openapi "github.com/xmtp/xmtp-node-go/pkg/proto/openapi"
Expand All @@ -33,6 +34,7 @@ import (
"github.com/pires/go-proxyproto"
messagev1 "github.com/xmtp/xmtp-node-go/pkg/api/message/v1"
apicontext "github.com/xmtp/xmtp-node-go/pkg/api/message/v1/context"
identityv1 "github.com/xmtp/xmtp-node-go/pkg/identity/api/v1"
mlsv1 "github.com/xmtp/xmtp-node-go/pkg/mls/api/v1"
)

Expand All @@ -51,6 +53,7 @@ type Server struct {
httpListener net.Listener
messagev1 *messagev1.Service
mlsv1 *mlsv1.Service
identityv1 *identityv1.Service
wg sync.WaitGroup
ctx context.Context
ctxCancel func()
Expand Down Expand Up @@ -155,13 +158,19 @@ func (s *Server) startGRPC() error {
}
proto.RegisterMessageApiServer(grpcServer, s.messagev1)

// Enable the MLS server if a store is provided
// Enable the MLS and identity servers if a store is provided
if s.Config.MLSStore != nil && s.Config.MLSValidator != nil && s.Config.EnableMls {
s.mlsv1, err = mlsv1.NewService(s.Log, s.Config.MLSStore, s.Config.MLSValidator, s.natsServer, publishToWakuRelay)
if err != nil {
return errors.Wrap(err, "creating mls service")
}
mlsv1pb.RegisterMlsApiServer(grpcServer, s.mlsv1)

s.identityv1, err = identityv1.NewService(s.Log, s.Config.MLSStore)
if err != nil {
return errors.Wrap(err, "creating identity service")
}
identityv1pb.RegisterIdentityApiServer(grpcServer, s.identityv1)
}

// Initialize waku relay subscription.
Expand Down Expand Up @@ -251,6 +260,11 @@ func (s *Server) startHTTP() error {
if err != nil {
return errors.Wrap(err, "registering mls handler")
}

err = identityv1pb.RegisterIdentityApiHandler(s.ctx, gwmux, conn)
if err != nil {
return errors.Wrap(err, "registering identity handler")
}
}

addr := addrString(s.HTTPAddress, s.HTTPPort)
Expand Down
2 changes: 1 addition & 1 deletion pkg/authn/authn.pb.go

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

54 changes: 54 additions & 0 deletions pkg/identity/api/v1/service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package api

import (
"context"

mlsstore "github.com/xmtp/xmtp-node-go/pkg/mls/store"
api "github.com/xmtp/xmtp-node-go/pkg/proto/identity/api/v1"
"go.uber.org/zap"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

type Service struct {
api.UnimplementedIdentityApiServer

log *zap.Logger
store mlsstore.MlsStore

ctx context.Context
ctxCancel func()
}

func NewService(log *zap.Logger, store mlsstore.MlsStore) (s *Service, err error) {
s = &Service{
log: log.Named("identity"),
store: store,
}
s.ctx, s.ctxCancel = context.WithCancel(context.Background())

s.log.Info("Starting identity service")
return s, nil
}

func (s *Service) Close() {
s.log.Info("closing")

if s.ctxCancel != nil {
s.ctxCancel()
}

s.log.Info("closed")
}

func (s *Service) PublishIdentityUpdate(ctx context.Context, req *api.PublishIdentityUpdateRequest) (*api.PublishIdentityUpdateResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "unimplemented")
}

func (s *Service) GetIdentityUpdates(ctx context.Context, req *api.GetIdentityUpdatesRequest) (*api.GetIdentityUpdatesResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "unimplemented")
}

func (s *Service) GetInboxIds(ctx context.Context, req *api.GetInboxIdsRequest) (*api.GetInboxIdsResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "unimplemented")
}
Loading
Loading