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

feat(framework) Add flwr login protos #4244

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
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
11 changes: 11 additions & 0 deletions src/proto/flwr/proto/exec.proto
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ service Exec {

// flwr ls command
rpc ListRuns(ListRunsRequest) returns (ListRunsResponse) {}

// Start login upon request
rpc Login(LoginRequest) returns (LoginResponse) {}

rpc GetAuthToken(GetAuthTokenRequest) returns (GetAuthTokenResponse) {}
}

message StartRunRequest {
Expand All @@ -52,3 +57,9 @@ message ListRunsResponse {
map<uint64, Run> run_dict = 1;
string now = 2;
}

message LoginRequest {}
message LoginResponse { map<string, string> login_details = 1; }
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we list out the login details needed, instead of using a dictionary? Just to make it clear.


message GetAuthTokenRequest { map<string, string> auth_details = 1; }
message GetAuthTokenResponse { map<string, string> auth_tokens = 1; }
Comment on lines +64 to +65
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above.

26 changes: 23 additions & 3 deletions src/py/flwr/proto/exec_pb2.py

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

81 changes: 81 additions & 0 deletions src/py/flwr/proto/exec_pb2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,84 @@ class ListRunsResponse(google.protobuf.message.Message):
) -> None: ...
def ClearField(self, field_name: typing_extensions.Literal["now",b"now","run_dict",b"run_dict"]) -> None: ...
global___ListRunsResponse = ListRunsResponse

class LoginRequest(google.protobuf.message.Message):
DESCRIPTOR: google.protobuf.descriptor.Descriptor
def __init__(self,
) -> None: ...
global___LoginRequest = LoginRequest

class LoginResponse(google.protobuf.message.Message):
DESCRIPTOR: google.protobuf.descriptor.Descriptor
class LoginDetailsEntry(google.protobuf.message.Message):
DESCRIPTOR: google.protobuf.descriptor.Descriptor
KEY_FIELD_NUMBER: builtins.int
VALUE_FIELD_NUMBER: builtins.int
key: typing.Text
value: typing.Text
def __init__(self,
*,
key: typing.Text = ...,
value: typing.Text = ...,
) -> None: ...
def ClearField(self, field_name: typing_extensions.Literal["key",b"key","value",b"value"]) -> None: ...

LOGIN_DETAILS_FIELD_NUMBER: builtins.int
@property
def login_details(self) -> google.protobuf.internal.containers.ScalarMap[typing.Text, typing.Text]: ...
def __init__(self,
*,
login_details: typing.Optional[typing.Mapping[typing.Text, typing.Text]] = ...,
) -> None: ...
def ClearField(self, field_name: typing_extensions.Literal["login_details",b"login_details"]) -> None: ...
global___LoginResponse = LoginResponse

class GetAuthTokenRequest(google.protobuf.message.Message):
DESCRIPTOR: google.protobuf.descriptor.Descriptor
class AuthDetailsEntry(google.protobuf.message.Message):
DESCRIPTOR: google.protobuf.descriptor.Descriptor
KEY_FIELD_NUMBER: builtins.int
VALUE_FIELD_NUMBER: builtins.int
key: typing.Text
value: typing.Text
def __init__(self,
*,
key: typing.Text = ...,
value: typing.Text = ...,
) -> None: ...
def ClearField(self, field_name: typing_extensions.Literal["key",b"key","value",b"value"]) -> None: ...

AUTH_DETAILS_FIELD_NUMBER: builtins.int
@property
def auth_details(self) -> google.protobuf.internal.containers.ScalarMap[typing.Text, typing.Text]: ...
def __init__(self,
*,
auth_details: typing.Optional[typing.Mapping[typing.Text, typing.Text]] = ...,
) -> None: ...
def ClearField(self, field_name: typing_extensions.Literal["auth_details",b"auth_details"]) -> None: ...
global___GetAuthTokenRequest = GetAuthTokenRequest

class GetAuthTokenResponse(google.protobuf.message.Message):
DESCRIPTOR: google.protobuf.descriptor.Descriptor
class AuthTokensEntry(google.protobuf.message.Message):
DESCRIPTOR: google.protobuf.descriptor.Descriptor
KEY_FIELD_NUMBER: builtins.int
VALUE_FIELD_NUMBER: builtins.int
key: typing.Text
value: typing.Text
def __init__(self,
*,
key: typing.Text = ...,
value: typing.Text = ...,
) -> None: ...
def ClearField(self, field_name: typing_extensions.Literal["key",b"key","value",b"value"]) -> None: ...

AUTH_TOKENS_FIELD_NUMBER: builtins.int
@property
def auth_tokens(self) -> google.protobuf.internal.containers.ScalarMap[typing.Text, typing.Text]: ...
def __init__(self,
*,
auth_tokens: typing.Optional[typing.Mapping[typing.Text, typing.Text]] = ...,
) -> None: ...
def ClearField(self, field_name: typing_extensions.Literal["auth_tokens",b"auth_tokens"]) -> None: ...
global___GetAuthTokenResponse = GetAuthTokenResponse
67 changes: 67 additions & 0 deletions src/py/flwr/proto/exec_pb2_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ def __init__(self, channel):
request_serializer=flwr_dot_proto_dot_exec__pb2.ListRunsRequest.SerializeToString,
response_deserializer=flwr_dot_proto_dot_exec__pb2.ListRunsResponse.FromString,
)
self.Login = channel.unary_unary(
'/flwr.proto.Exec/Login',
request_serializer=flwr_dot_proto_dot_exec__pb2.LoginRequest.SerializeToString,
response_deserializer=flwr_dot_proto_dot_exec__pb2.LoginResponse.FromString,
)
self.GetAuthToken = channel.unary_unary(
'/flwr.proto.Exec/GetAuthToken',
request_serializer=flwr_dot_proto_dot_exec__pb2.GetAuthTokenRequest.SerializeToString,
response_deserializer=flwr_dot_proto_dot_exec__pb2.GetAuthTokenResponse.FromString,
)


class ExecServicer(object):
Expand All @@ -55,6 +65,19 @@ def ListRuns(self, request, context):
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')

def Login(self, request, context):
"""Start login upon request
"""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')

def GetAuthToken(self, request, context):
"""Missing associated documentation comment in .proto file."""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')


def add_ExecServicer_to_server(servicer, server):
rpc_method_handlers = {
Expand All @@ -73,6 +96,16 @@ def add_ExecServicer_to_server(servicer, server):
request_deserializer=flwr_dot_proto_dot_exec__pb2.ListRunsRequest.FromString,
response_serializer=flwr_dot_proto_dot_exec__pb2.ListRunsResponse.SerializeToString,
),
'Login': grpc.unary_unary_rpc_method_handler(
servicer.Login,
request_deserializer=flwr_dot_proto_dot_exec__pb2.LoginRequest.FromString,
response_serializer=flwr_dot_proto_dot_exec__pb2.LoginResponse.SerializeToString,
),
'GetAuthToken': grpc.unary_unary_rpc_method_handler(
servicer.GetAuthToken,
request_deserializer=flwr_dot_proto_dot_exec__pb2.GetAuthTokenRequest.FromString,
response_serializer=flwr_dot_proto_dot_exec__pb2.GetAuthTokenResponse.SerializeToString,
),
}
generic_handler = grpc.method_handlers_generic_handler(
'flwr.proto.Exec', rpc_method_handlers)
Expand Down Expand Up @@ -133,3 +166,37 @@ def ListRuns(request,
flwr_dot_proto_dot_exec__pb2.ListRunsResponse.FromString,
options, channel_credentials,
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)

@staticmethod
def Login(request,
target,
options=(),
channel_credentials=None,
call_credentials=None,
insecure=False,
compression=None,
wait_for_ready=None,
timeout=None,
metadata=None):
return grpc.experimental.unary_unary(request, target, '/flwr.proto.Exec/Login',
flwr_dot_proto_dot_exec__pb2.LoginRequest.SerializeToString,
flwr_dot_proto_dot_exec__pb2.LoginResponse.FromString,
options, channel_credentials,
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)

@staticmethod
def GetAuthToken(request,
target,
options=(),
channel_credentials=None,
call_credentials=None,
insecure=False,
compression=None,
wait_for_ready=None,
timeout=None,
metadata=None):
return grpc.experimental.unary_unary(request, target, '/flwr.proto.Exec/GetAuthToken',
flwr_dot_proto_dot_exec__pb2.GetAuthTokenRequest.SerializeToString,
flwr_dot_proto_dot_exec__pb2.GetAuthTokenResponse.FromString,
options, channel_credentials,
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
23 changes: 23 additions & 0 deletions src/py/flwr/proto/exec_pb2_grpc.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ class ExecStub:
flwr.proto.exec_pb2.ListRunsResponse]
"""flwr ls command"""

Login: grpc.UnaryUnaryMultiCallable[
flwr.proto.exec_pb2.LoginRequest,
flwr.proto.exec_pb2.LoginResponse]
"""Start login upon request"""

GetAuthToken: grpc.UnaryUnaryMultiCallable[
flwr.proto.exec_pb2.GetAuthTokenRequest,
flwr.proto.exec_pb2.GetAuthTokenResponse]


class ExecServicer(metaclass=abc.ABCMeta):
@abc.abstractmethod
Expand All @@ -50,5 +59,19 @@ class ExecServicer(metaclass=abc.ABCMeta):
"""flwr ls command"""
pass

@abc.abstractmethod
def Login(self,
request: flwr.proto.exec_pb2.LoginRequest,
context: grpc.ServicerContext,
) -> flwr.proto.exec_pb2.LoginResponse:
"""Start login upon request"""
pass

@abc.abstractmethod
def GetAuthToken(self,
request: flwr.proto.exec_pb2.GetAuthTokenRequest,
context: grpc.ServicerContext,
) -> flwr.proto.exec_pb2.GetAuthTokenResponse: ...


def add_ExecServicer_to_server(servicer: ExecServicer, server: grpc.Server) -> None: ...
18 changes: 18 additions & 0 deletions src/py/flwr/superexec/exec_servicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@
)
from flwr.proto import exec_pb2_grpc # pylint: disable=E0611
from flwr.proto.exec_pb2 import ( # pylint: disable=E0611
GetAuthTokenRequest,
GetAuthTokenResponse,
ListRunsRequest,
ListRunsResponse,
LoginRequest,
LoginResponse,
StartRunRequest,
StartRunResponse,
StreamLogsRequest,
Expand Down Expand Up @@ -126,6 +130,20 @@ def ListRuns(
# Handle `flwr ls --run-id <run_id>`
return _create_list_runs_response({request.run_id}, state)

def Login(
self, request: LoginRequest, context: grpc.ServicerContext
) -> LoginResponse:
"""Start login."""
log(INFO, "ExecServicer.Login")
return LoginResponse(login_details={})

def GetAuthToken(
self, request: GetAuthTokenRequest, context: grpc.ServicerContext
) -> GetAuthTokenResponse:
"""Get auth token."""
log(INFO, "ExecServicer.GetAuthToken")
return GetAuthTokenResponse(auth_tokens={})


def _create_list_runs_response(run_ids: set[int], state: LinkState) -> ListRunsResponse:
"""Create response for `flwr ls --runs` and `flwr ls --run-id <run_id>`."""
Expand Down