Skip to content

Commit

Permalink
[PC-924] GRPC Service for Org Resolver
Browse files Browse the repository at this point in the history
Summary: For Org resolver, write out a grpc service to be used.

Test Plan: Unit test & Manual

Reviewers: nserrino, michelle, philkuz, vihang

Reviewed By: michelle

JIRA Issues: PC-924

Differential Revision: https://phab.corp.pixielabs.ai/D8767
  • Loading branch information
vishjain committed May 28, 2021
1 parent 4870092 commit f39fcde
Show file tree
Hide file tree
Showing 9 changed files with 2,179 additions and 359 deletions.
2,222 changes: 1,907 additions & 315 deletions src/api/proto/cloudpb/cloudapi.pb.go

Large diffs are not rendered by default.

43 changes: 42 additions & 1 deletion src/api/proto/cloudpb/cloudapi.proto
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ import "src/api/proto/vispb/vis.proto";
service OrganizationService {
// Create an Invite Link that a new user can follow to create a password for their account.
rpc InviteUser(InviteUserRequest) returns (InviteUserResponse);
rpc GetOrg(px.uuidpb.UUID) returns (OrgInfo);
rpc UpdateOrg(UpdateOrgRequest) returns (OrgInfo);
rpc GetUsersInOrg(GetUsersInOrgRequest) returns (GetUsersInOrgResponse);
}

message InviteUserRequest {
Expand Down Expand Up @@ -631,4 +634,42 @@ message OrgInfo {
px.uuidpb.UUID id = 1 [ (gogoproto.customname) = "ID" ];
// The name of the organization.
string org_name = 2;
}
// The last part of their email.
string domain_name = 3;
// Whether this org requires admin approval to authorize new users.
bool enable_approvals = 4;
}

message UpdateOrgRequest {
// The ID of the org.
px.uuidpb.UUID id = 1 [(gogoproto.customname) = "ID"];
// Whether to enable/disable the requirement for admins to approve new users.
google.protobuf.BoolValue enable_approvals = 2;
}

// A request to get all users in the given org. This org must match the user's org,
// verified in the augmented token.
message GetUsersInOrgRequest {
// The org to get the users of.
px.uuidpb.UUID org_id = 1 [(gogoproto.customname) = "OrgID"];
}

// The response to a GetUsersInOrgRequest.
message GetUsersInOrgResponse {
// The users in the requested org.
repeated UserInfo users = 1;
}

// UserInfo has information about a single end user in our system.
message UserInfo {
// The ID of the user.
px.uuidpb.UUID id = 1 [(gogoproto.customname) = "ID"];
// The ID of the organization that they belong to.
px.uuidpb.UUID org_id = 2 [(gogoproto.customname) = "OrgID"];
string username = 3;
string first_name = 4;
string last_name = 5;
string email = 6;
string profile_picture = 7;
bool is_approved = 8;
}
105 changes: 105 additions & 0 deletions src/api/proto/cloudpb/mock/cloudapi_mock.gen.go

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

5 changes: 4 additions & 1 deletion src/cloud/api/api_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,17 @@ func main() {
profileServer := &controller.ProfileServer{ProfileServiceClient: pc}
cloudpb.RegisterProfileServiceServer(s.GRPCServer(), profileServer)

os := &controller.OrganizationServiceServer{ProfileServiceClient: pc}
cloudpb.RegisterOrganizationServiceServer(s.GRPCServer(), os)

gqlEnv := controller.GraphQLEnv{
ArtifactTrackerServer: artifactTrackerServer,
VizierClusterInfo: cis,
VizierDeployKeyMgr: vdks,
APIKeyMgr: aks,
ScriptMgrServer: sms,
AutocompleteServer: as,
OrgServer: profileServer,
OrgServer: os,
ProfileServiceClient: pc,
}

Expand Down
3 changes: 1 addition & 2 deletions src/cloud/api/controller/gql.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ type GraphQLEnv struct {
ScriptMgrServer cloudpb.ScriptMgrServer
AutocompleteServer cloudpb.AutocompleteServiceServer
OrgServer cloudpb.OrganizationServiceServer

ProfileServiceClient profilepb.ProfileServiceClient
ProfileServiceClient profilepb.ProfileServiceClient
}

// QueryResolver resolves queries for GQL.
Expand Down
88 changes: 86 additions & 2 deletions src/cloud/api/controller/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -820,8 +820,13 @@ func (p *ProfileServer) GetOrgInfo(ctx context.Context, req *uuidpb.UUID) (*clou
}, nil
}

// OrganizationServiceServer is the server that implements the OrganizationService gRPC service.
type OrganizationServiceServer struct {
ProfileServiceClient profilepb.ProfileServiceClient
}

// InviteUser creates and returns an invite link for the org for the specified user info.
func (p *ProfileServer) InviteUser(ctx context.Context, externalReq *cloudpb.InviteUserRequest) (*cloudpb.InviteUserResponse, error) {
func (o *OrganizationServiceServer) InviteUser(ctx context.Context, externalReq *cloudpb.InviteUserRequest) (*cloudpb.InviteUserResponse, error) {
ctx, err := contextWithAuthToken(ctx)
if err != nil {
return nil, err
Expand All @@ -844,7 +849,7 @@ func (p *ProfileServer) InviteUser(ctx context.Context, externalReq *cloudpb.Inv
LastName: externalReq.LastName,
MustCreateUser: true,
}
resp, err := p.ProfileServiceClient.InviteUser(ctx, internalReq)
resp, err := o.ProfileServiceClient.InviteUser(ctx, internalReq)
if err != nil {
return nil, err
}
Expand All @@ -854,3 +859,82 @@ func (p *ProfileServer) InviteUser(ctx context.Context, externalReq *cloudpb.Inv
InviteLink: resp.InviteLink,
}, nil
}

// GetOrg will retrieve org based on uuid.
func (o *OrganizationServiceServer) GetOrg(ctx context.Context, req *uuidpb.UUID) (*cloudpb.OrgInfo, error) {
ctx, err := contextWithAuthToken(ctx)
if err != nil {
return nil, err
}

resp, err := o.ProfileServiceClient.GetOrg(ctx, req)
if err != nil {
return nil, err
}

return &cloudpb.OrgInfo{
ID: resp.ID,
OrgName: resp.OrgName,
DomainName: resp.DomainName,
EnableApprovals: resp.EnableApprovals,
}, nil
}

// UpdateOrg will update org approval details.
func (o *OrganizationServiceServer) UpdateOrg(ctx context.Context, req *cloudpb.UpdateOrgRequest) (*cloudpb.OrgInfo, error) {
ctx, err := contextWithAuthToken(ctx)
if err != nil {
return nil, err
}

resp, err := o.ProfileServiceClient.UpdateOrg(ctx, &profilepb.UpdateOrgRequest{
ID: req.ID,
EnableApprovals: req.EnableApprovals,
})
if err != nil {
return nil, err
}

return &cloudpb.OrgInfo{
ID: resp.ID,
OrgName: resp.OrgName,
DomainName: resp.DomainName,
EnableApprovals: resp.EnableApprovals,
}, nil
}

// GetUsersInOrg will get users given an org id.
func (o *OrganizationServiceServer) GetUsersInOrg(ctx context.Context, req *cloudpb.GetUsersInOrgRequest) (*cloudpb.GetUsersInOrgResponse,
error) {
ctx, err := contextWithAuthToken(ctx)
if err != nil {
return nil, err
}

inReq := &profilepb.GetUsersInOrgRequest{
OrgID: req.OrgID,
}

resp, err := o.ProfileServiceClient.GetUsersInOrg(ctx, inReq)
if err != nil {
return nil, err
}

userList := make([]*cloudpb.UserInfo, len(resp.Users))
for idx, user := range resp.Users {
userList[idx] = &cloudpb.UserInfo{
ID: user.ID,
OrgID: user.OrgID,
Username: user.Username,
FirstName: user.FirstName,
LastName: user.LastName,
Email: user.Email,
ProfilePicture: user.ProfilePicture,
IsApproved: user.IsApproved,
}
}

return &cloudpb.GetUsersInOrgResponse{
Users: userList,
}, nil
}
6 changes: 3 additions & 3 deletions src/cloud/api/controller/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,7 @@ func TestProfileServer_GetOrgInfo(t *testing.T) {
assert.Equal(t, orgID, resp.ID)
}

func TestProfileServer_InviteUser(t *testing.T) {
func TestOrganizationServiceServer_InviteUser(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

Expand All @@ -1088,9 +1088,9 @@ func TestProfileServer_InviteUser(t *testing.T) {
InviteLink: "withpixie.ai/invite&id=abcd",
}, nil)

profileServer := &controller.ProfileServer{mockClients.MockProfile}
os := &controller.OrganizationServiceServer{mockClients.MockProfile}

resp, err := profileServer.InviteUser(ctx, &cloudpb.InviteUserRequest{
resp, err := os.InviteUser(ctx, &cloudpb.InviteUserRequest{
Email: "bobloblaw@lawblog.law",
FirstName: "bob",
LastName: "loblaw",
Expand Down
Loading

0 comments on commit f39fcde

Please sign in to comment.