From 9bbd18d35f8b0c6a2ca519c4f9e76acd0b36d172 Mon Sep 17 00:00:00 2001 From: Konstantinos Feretos Date: Wed, 10 Jan 2024 17:24:31 +0200 Subject: [PATCH] feat(authentication): Add/RemoveTeamMembers gRPC rpcs (#885) * feat(authentication): Add/RemoveTeamMembers gRPC rpcs * fix(authentication): Add/RemoveTeamMembers rpcs missing teamId validation --- .../src/modules/authentication/index.ts | 14 ++++- modules/authentication/src/Authentication.ts | 56 ++++++++++++++++++- .../authentication/src/authentication.proto | 8 +++ 3 files changed, 76 insertions(+), 2 deletions(-) diff --git a/libraries/grpc-sdk/src/modules/authentication/index.ts b/libraries/grpc-sdk/src/modules/authentication/index.ts index 17fc8b39f..fdab27ec9 100644 --- a/libraries/grpc-sdk/src/modules/authentication/index.ts +++ b/libraries/grpc-sdk/src/modules/authentication/index.ts @@ -10,7 +10,11 @@ import { } from '../../protoUtils'; export class Authentication extends ConduitModule { - constructor(private readonly moduleName: string, url: string, grpcToken?: string) { + constructor( + private readonly moduleName: string, + url: string, + grpcToken?: string, + ) { super(moduleName, 'authentication', url, grpcToken); this.initializeClient(AuthenticationDefinition); } @@ -47,6 +51,14 @@ export class Authentication extends ConduitModule { createTeam: this.createTeam.bind(this), teamDelete: this.teamDelete.bind(this), validateAccessToken: this.validateAccessToken.bind(this), + addTeamMembers: this.addTeamMembers.bind(this), + removeTeamMembers: this.removeTeamMembers.bind(this), }, }; protected metricsSchema = metricsSchema; @@ -383,6 +387,56 @@ export default class Authentication extends ManagedModule { return callback(null, { message: result as string }); } + async addTeamMembers( + call: GrpcRequest, + callback: GrpcCallback, + ) { + const teamId = call.request.teamId; + if (isEmpty(teamId)) { + return callback({ + code: status.INVALID_ARGUMENT, + message: 'teamId must be a valid Team ID!', + }); + } + const urlParams = { team: teamId }; + const bodyParams = { members: call.request.memberIds }; + const request = createParsedRouterRequest( + { ...urlParams, ...bodyParams }, + urlParams, + undefined, + bodyParams, + ); + await new TeamsAdmin(this.grpcSdk).addTeamMembers(request).catch(e => { + return callback({ code: status.INTERNAL, message: (e as Error).message }); + }); + return callback(null, {}); + } + + async removeTeamMembers( + call: GrpcRequest, + callback: GrpcCallback, + ) { + const teamId = call.request.teamId; + if (isEmpty(teamId)) { + return callback({ + code: status.INVALID_ARGUMENT, + message: 'teamId must be a valid Team ID!', + }); + } + const urlParams = { team: teamId }; + const bodyParams = { members: call.request.memberIds }; + const request = createParsedRouterRequest( + { ...urlParams, ...bodyParams }, + urlParams, + undefined, + bodyParams, + ); + await new TeamsAdmin(this.grpcSdk).removeTeamMembers(request).catch(e => { + return callback({ code: status.INTERNAL, message: (e as Error).message }); + }); + return callback(null, {}); + } + async validateAccessToken( call: GrpcRequest, callback: GrpcCallback, diff --git a/modules/authentication/src/authentication.proto b/modules/authentication/src/authentication.proto index 63c543593..ca11e47e7 100644 --- a/modules/authentication/src/authentication.proto +++ b/modules/authentication/src/authentication.proto @@ -1,4 +1,5 @@ syntax = "proto3"; +import "google/protobuf/empty.proto"; package authentication; message UserLoginRequest { @@ -59,6 +60,11 @@ message TeamDeleteResponse { string message = 1; } +message ModifyTeamMembersRequest { + string teamId = 1; + repeated string memberIds = 2; +} + message ValidateAccessTokenRequest { string accessToken = 1; optional string path = 2; @@ -83,5 +89,7 @@ service Authentication { rpc GetTeam(GetTeamRequest) returns (Team); rpc CreateTeam(CreateTeamRequest) returns (Team); rpc TeamDelete(TeamDeleteRequest) returns (TeamDeleteResponse); + rpc AddTeamMembers(ModifyTeamMembersRequest) returns (google.protobuf.Empty); + rpc RemoveTeamMembers(ModifyTeamMembersRequest) returns (google.protobuf.Empty); rpc ValidateAccessToken(ValidateAccessTokenRequest) returns (ValidateAccessTokenResponse); }