package caps import ( "context" abiv1 "git.dev.alexdunmow.com/block/pluginsdk/abi/v1" "git.dev.alexdunmow.com/block/pluginsdk/auth" "github.com/google/uuid" ) // usersStub implements auth.PublicUsers over users.* capability calls. type usersStub struct{ base } var _ auth.PublicUsers = (*usersStub)(nil) func (s *usersStub) GetByUsername(ctx context.Context, username string) (*auth.PublicUserProfile, error) { resp := &abiv1.UsersGetByUsernameResponse{} req := &abiv1.UsersGetByUsernameRequest{Username: username} if err := s.invoke(ctx, "get_by_username", req, resp); err != nil { return nil, err } return publicUserFromProto(resp.GetUser()), nil } func (s *usersStub) GetByID(ctx context.Context, id uuid.UUID) (*auth.PublicUserProfile, error) { resp := &abiv1.UsersGetByIdResponse{} if err := s.invoke(ctx, "get_by_id", &abiv1.UsersGetByIdRequest{Id: id.String()}, resp); err != nil { return nil, err } return publicUserFromProto(resp.GetUser()), nil } func publicUserFromProto(u *abiv1.PublicUserProfile) *auth.PublicUserProfile { if u == nil { return nil } return &auth.PublicUserProfile{ ID: parseUUID(u.GetId()), Email: u.GetEmail(), Username: u.GetUsername(), DisplayName: u.GetDisplayName(), AvatarURL: u.GetAvatarUrl(), Bio: u.GetBio(), EmailVerified: u.GetEmailVerified(), Role: u.GetRole(), } }