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 user auth CLI integration #4602

Merged
merged 163 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
163 commits
Select commit Hold shift + click to select a range
d103055
Add Login RPC
danielnugraha Sep 20, 2024
3bbc214
Generate updated proto
danielnugraha Sep 20, 2024
f7f06aa
Add login servicer
danielnugraha Sep 20, 2024
da31e25
Format
danielnugraha Sep 20, 2024
211bc3a
Format
danielnugraha Sep 20, 2024
5ff2e9e
Update proto definition
danielnugraha Nov 24, 2024
7fe6a39
Format
danielnugraha Nov 24, 2024
f8d6b2c
Format
danielnugraha Nov 24, 2024
158677f
Format
danielnugraha Nov 24, 2024
f229f94
Add generic and keycloak auth plugin
danielnugraha Nov 24, 2024
ed1ba5f
Format
danielnugraha Nov 24, 2024
8e874a4
Format
danielnugraha Nov 24, 2024
c3dd946
Merge branch 'add-flwr-login' into add-keycloak-auth-plugin
danielnugraha Nov 24, 2024
ecaa642
Format
danielnugraha Nov 24, 2024
b090981
Format
danielnugraha Nov 27, 2024
332e74a
Format
danielnugraha Nov 27, 2024
13ebe96
Format
danielnugraha Nov 27, 2024
4c373a7
Merge branch 'main' into add-keycloak-auth-plugin
danielnugraha Nov 27, 2024
8a3980f
Format
danielnugraha Nov 27, 2024
846bf86
Merge remote-tracking branch 'refs/remotes/origin/add-keycloak-auth-p…
danielnugraha Nov 27, 2024
04ab69c
Merge remote-tracking branch 'origin' into add-keycloak-auth-plugin
danielnugraha Nov 28, 2024
511ac60
Add Keycloak CLI user auth integration
danielnugraha Nov 28, 2024
74c9dc8
Format
danielnugraha Nov 28, 2024
5cf69a4
Format
danielnugraha Nov 28, 2024
f73ba55
Move try obtain credentials
danielnugraha Nov 28, 2024
6a2ceba
Move try obtain credentials
danielnugraha Nov 28, 2024
0ea9e28
Merge branch 'main' into add-keycloak-cli
danielnugraha Nov 28, 2024
b042a49
Merge remote-tracking branch 'origin' into add-flwr-login
danielnugraha Dec 2, 2024
ab1d7da
Merge remote-tracking branch 'origin' into add-flwr-login
danielnugraha Dec 3, 2024
a176c39
Add abstract user auth plugin
danielnugraha Dec 3, 2024
169643d
Update src/py/flwr/common/auth_plugin/auth_plugin.py
danielnugraha Dec 3, 2024
c3742c2
Update src/py/flwr/common/auth_plugin/auth_plugin.py
danielnugraha Dec 3, 2024
f76b4f8
Update src/py/flwr/common/auth_plugin/auth_plugin.py
danielnugraha Dec 3, 2024
999ef9f
Update src/py/flwr/common/auth_plugin/auth_plugin.py
danielnugraha Dec 3, 2024
64af28b
format
panh99 Dec 3, 2024
bb57e65
Add keycloak auth plugin
danielnugraha Dec 3, 2024
2cf548d
Format
danielnugraha Dec 3, 2024
0fd4ac6
Merge keycloak plugin
danielnugraha Dec 3, 2024
bb15bb2
Merge keycloak plugin
danielnugraha Dec 3, 2024
6a65e82
Move auth plugin to ee
danielnugraha Dec 3, 2024
005ae81
Format
danielnugraha Dec 3, 2024
1b0c816
Format
danielnugraha Dec 3, 2024
f0cdf17
Update src/py/flwr/common/auth_plugin/auth_plugin.py
danielnugraha Dec 3, 2024
a8a66b7
Update src/py/flwr/common/auth_plugin/auth_plugin.py
danielnugraha Dec 3, 2024
2f66fa9
Update src/py/flwr/common/auth_plugin/auth_plugin.py
danielnugraha Dec 3, 2024
3e437a1
Update src/py/flwr/common/auth_plugin/auth_plugin.py
danielnugraha Dec 3, 2024
31afe5a
Update src/py/flwr/common/auth_plugin/auth_plugin.py
danielnugraha Dec 3, 2024
20966b9
Update src/py/flwr/cli/login/login.py
danielnugraha Dec 4, 2024
ff70c15
Update src/py/flwr/cli/login/login.py
danielnugraha Dec 4, 2024
45b0548
Update src/py/flwr/cli/login/login.py
danielnugraha Dec 4, 2024
46295a6
Reuse
danielnugraha Dec 4, 2024
e2f24fb
Merge remote-tracking branch 'refs/remotes/origin/add-keycloak-cli' i…
danielnugraha Dec 4, 2024
e7cf0ae
Format
danielnugraha Dec 4, 2024
b91c0c9
Change proto naming
danielnugraha Dec 4, 2024
57da1e5
Merge branch 'add-flwr-login' into add-abc-auth-plugin
danielnugraha Dec 4, 2024
01658da
Change naming
danielnugraha Dec 4, 2024
ecc21f4
Merge branch 'add-abc-auth-plugin' into add-keycloak-cli
danielnugraha Dec 4, 2024
21c7c17
Change naming
danielnugraha Dec 4, 2024
fcdc151
Format
danielnugraha Dec 4, 2024
ea6ef11
Format
danielnugraha Dec 4, 2024
fda2b4f
Merge branch 'main' into add-flwr-login
danielnugraha Dec 4, 2024
3b94ddf
Recompile protos
danielnugraha Dec 4, 2024
e0a09ba
Merge remote-tracking branch 'refs/remotes/origin/add-flwr-login' int…
danielnugraha Dec 4, 2024
db9242b
Merge branch 'add-flwr-login' into add-abc-auth-plugin
danielnugraha Dec 4, 2024
00d249a
Format
danielnugraha Dec 4, 2024
e51d97b
Format
danielnugraha Dec 4, 2024
23c2579
Merge remote-tracking branch 'origin/main' into add-flwr-login
panh99 Dec 4, 2024
eb85eec
recompile
panh99 Dec 4, 2024
d986f0d
fix log message
panh99 Dec 4, 2024
35cd61b
Merge branch 'main' into add-flwr-login
panh99 Dec 4, 2024
36cc1a8
Add abstract user auth plugin
danielnugraha Dec 3, 2024
195bc2b
Update src/py/flwr/common/auth_plugin/auth_plugin.py
danielnugraha Dec 3, 2024
77e7888
Update src/py/flwr/common/auth_plugin/auth_plugin.py
danielnugraha Dec 3, 2024
cded5da
Update src/py/flwr/common/auth_plugin/auth_plugin.py
danielnugraha Dec 3, 2024
a42bb09
Update src/py/flwr/common/auth_plugin/auth_plugin.py
danielnugraha Dec 3, 2024
78ff704
format
panh99 Dec 3, 2024
e7fe4b5
Update src/py/flwr/common/auth_plugin/auth_plugin.py
danielnugraha Dec 3, 2024
4ec67f8
Update src/py/flwr/common/auth_plugin/auth_plugin.py
danielnugraha Dec 3, 2024
130d4ec
Update src/py/flwr/common/auth_plugin/auth_plugin.py
danielnugraha Dec 3, 2024
a696325
Update src/py/flwr/common/auth_plugin/auth_plugin.py
danielnugraha Dec 3, 2024
1851619
Update src/py/flwr/common/auth_plugin/auth_plugin.py
danielnugraha Dec 3, 2024
27bc9ee
Change naming
danielnugraha Dec 4, 2024
09e2c3c
Format
danielnugraha Dec 4, 2024
f925210
Format
danielnugraha Dec 4, 2024
efcf3ea
Add keycloak auth plugin
danielnugraha Dec 3, 2024
742980a
Format
danielnugraha Dec 3, 2024
74385dc
Format
danielnugraha Dec 4, 2024
77b0e22
Format
danielnugraha Dec 4, 2024
ba0098e
update with add-abc-auth-plugin branch
panh99 Dec 4, 2024
5ba1d2a
Add keycloak auth plugin
danielnugraha Dec 3, 2024
379f097
Format
danielnugraha Dec 3, 2024
df0ba9c
Format
danielnugraha Dec 4, 2024
acf0238
Format
danielnugraha Dec 4, 2024
fed63a0
Rebase
danielnugraha Dec 4, 2024
f67c867
Merge remote-tracking branch 'refs/remotes/origin/add-abc-auth-plugin…
danielnugraha Dec 4, 2024
0036239
init
panh99 Dec 4, 2024
ac839bb
format
panh99 Dec 4, 2024
189f168
Merge
danielnugraha Dec 4, 2024
21eed59
Format
danielnugraha Dec 4, 2024
f880fa6
Merge branch 'add-abc-auth-plugin' into add-keycloak-cli
danielnugraha Dec 4, 2024
a0ed81a
Unify store tokens
danielnugraha Dec 4, 2024
4ed3085
Delete ee
danielnugraha Dec 4, 2024
f94eac7
update docstring
panh99 Dec 4, 2024
91038f6
Merge remote-tracking branch 'origin/add-abc-auth-plugin' into add-ke…
panh99 Dec 4, 2024
6d0115e
fix mypy/pylint errors
panh99 Dec 4, 2024
98f21f9
Merge branch 'main' into add-keycloak-cli
panh99 Dec 4, 2024
069ba42
use util function
panh99 Dec 4, 2024
2493e4d
add new method
panh99 Dec 4, 2024
bceede6
rm new method
panh99 Dec 4, 2024
ed46d40
update doc
panh99 Dec 4, 2024
cd43e7e
Merge branch 'add-abc-auth-plugin' into add-keycloak-cli
panh99 Dec 5, 2024
1410263
update
panh99 Dec 5, 2024
f5f159a
Merge main
danielnugraha Dec 5, 2024
5d3eb8b
Merge branch 'add-flwr-login' into add-abc-auth-plugin
danielnugraha Dec 5, 2024
1bdc962
Merge
danielnugraha Dec 5, 2024
487f2ff
Merge
danielnugraha Dec 5, 2024
b9b9c9c
Format
danielnugraha Dec 5, 2024
f90139e
fix merge
panh99 Dec 6, 2024
473cd86
init
panh99 Dec 6, 2024
ac1d024
Merge branch 'add-abc-auth-plugin' into add-keycloak-cli
panh99 Dec 6, 2024
6be0d5d
update
panh99 Dec 6, 2024
d939bc5
fix docstring
panh99 Dec 6, 2024
134cec6
Merge branch 'add-abc-auth-plugin' into add-keycloak-cli
panh99 Dec 6, 2024
39b1858
restructure
panh99 Dec 7, 2024
a51df70
format
panh99 Dec 7, 2024
9ee0113
renaming
panh99 Dec 7, 2024
2443c2a
Merge branch 'main' into add-keycloak-cli
panh99 Dec 7, 2024
987ce53
Merge branch 'main' into add-flwr-login
panh99 Dec 7, 2024
582530f
init
panh99 Dec 6, 2024
d7bf08c
fix docstring
panh99 Dec 6, 2024
fe77ca3
add doc
panh99 Dec 6, 2024
ac88a18
fix wording
panh99 Dec 6, 2024
e3e2908
improve type hint
panh99 Dec 7, 2024
83fefdc
optimise utils
panh99 Dec 8, 2024
2edf2ba
fix a bug
panh99 Dec 8, 2024
0ec2a9d
Update src/py/flwr/common/auth_plugin/auth_plugin.py
panh99 Dec 8, 2024
61ab327
Merge branch 'main' into add-abc-auth-plugin
panh99 Dec 9, 2024
d12acfe
Merge branch 'add-abc-auth-plugin' into add-keycloak-cli
panh99 Dec 9, 2024
a97c39c
update typing
panh99 Dec 9, 2024
801e11a
Merge branch 'add-abc-auth-plugin' into add-keycloak-cli
panh99 Dec 9, 2024
fda133e
update usage
panh99 Dec 9, 2024
cc18348
update doc
panh99 Dec 9, 2024
81d26d2
Merge branch 'add-abc-auth-plugin' into add-keycloak-cli
panh99 Dec 9, 2024
2f197e7
apply user auth to all clis
panh99 Dec 9, 2024
a71bc8c
rm unnecessary args
panh99 Dec 10, 2024
14709af
update usage
panh99 Dec 10, 2024
6a52390
Merge branch 'add-abc-auth-plugin' into add-keycloak-cli
panh99 Dec 10, 2024
9e92852
sync
panh99 Dec 10, 2024
458c67c
Merge remote-tracking branch 'origin/main' into add-keycloak-cli
panh99 Dec 10, 2024
35d7779
update importing
panh99 Dec 10, 2024
f8f829f
update error message
panh99 Dec 10, 2024
aab7269
enable unary-stream
panh99 Dec 10, 2024
0794b4e
format and update error message
panh99 Dec 10, 2024
efb7781
update error msg
panh99 Dec 10, 2024
caacb7a
renaming
panh99 Dec 10, 2024
171255f
improve help message
panh99 Dec 10, 2024
7c6bd0c
Merge remote-tracking branch 'origin/main' into add-keycloak-cli
panh99 Dec 10, 2024
b31eff8
Update src/py/flwr/cli/login/login.py
panh99 Dec 10, 2024
bcd1a9b
use constant
panh99 Dec 11, 2024
99feacb
update util
panh99 Dec 11, 2024
7494012
mv load_tokens out from init, and improve docstring
panh99 Dec 11, 2024
eeb1d54
fix mypy
panh99 Dec 11, 2024
89eb73e
Merge branch 'main' into add-keycloak-cli
panh99 Dec 11, 2024
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
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ pyyaml = "^6.0.2"
requests = "^2.31.0"
# Optional dependencies (Simulation Engine)
ray = { version = "==2.10.0", optional = true, python = ">=3.9,<3.12" }
# Optional dependencies (REST transport layer)
starlette = { version = "^0.31.0", optional = true }
uvicorn = { version = "^0.23.0", extras = ["standard"], optional = true }

Expand Down
2 changes: 2 additions & 0 deletions src/py/flwr/cli/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from .build import build
from .install import install
from .log import log
from .login import login
from .ls import ls
from .new import new
from .run import run
Expand All @@ -41,6 +42,7 @@
app.command()(log)
app.command()(ls)
app.command()(stop)
app.command()(login)

typer_click_object = get_command(app)

Expand Down
86 changes: 86 additions & 0 deletions src/py/flwr/cli/cli_user_auth_interceptor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Copyright 2024 Flower Labs GmbH. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Flower run interceptor."""


from typing import Any, Callable, Union

import grpc

from flwr.common.auth_plugin import CliAuthPlugin
from flwr.proto.exec_pb2 import ( # pylint: disable=E0611
StartRunRequest,
StreamLogsRequest,
)

Request = Union[
StartRunRequest,
StreamLogsRequest,
]


class CliUserAuthInterceptor(
grpc.UnaryUnaryClientInterceptor, grpc.UnaryStreamClientInterceptor # type: ignore
):
"""CLI interceptor for user authentication."""

def __init__(self, auth_plugin: CliAuthPlugin):
self.auth_plugin = auth_plugin

def _authenticated_call(
self,
continuation: Callable[[Any, Any], Any],
client_call_details: grpc.ClientCallDetails,
request: Request,
) -> grpc.Call:
"""Send and receive tokens via metadata."""
new_metadata = self.auth_plugin.write_tokens_to_metadata(
client_call_details.metadata or []
)

details = client_call_details._replace(metadata=new_metadata)

response = continuation(details, request)
if response.initial_metadata():
retrieved_metadata = dict(response.initial_metadata())
self.auth_plugin.store_tokens(retrieved_metadata)

return response

def intercept_unary_unary(
self,
continuation: Callable[[Any, Any], Any],
client_call_details: grpc.ClientCallDetails,
request: Request,
) -> grpc.Call:
"""Intercept a unary-unary call for user authentication.

This method intercepts a unary-unary RPC call initiated from the CLI and adds
the required authentication tokens to the RPC metadata.
"""
return self._authenticated_call(continuation, client_call_details, request)

def intercept_unary_stream(
self,
continuation: Callable[[Any, Any], Any],
client_call_details: grpc.ClientCallDetails,
request: Request,
) -> grpc.Call:
"""Intercept a unary-stream call for user authentication.

This method intercepts a unary-stream RPC call initiated from the CLI and adds
the required authentication tokens to the RPC metadata.
"""
return self._authenticated_call(continuation, client_call_details, request)
26 changes: 6 additions & 20 deletions src/py/flwr/cli/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@

from flwr.cli.config_utils import (
load_and_validate,
validate_certificate_in_federation_config,
validate_federation_in_project_config,
validate_project_config,
)
from flwr.common.constant import CONN_RECONNECT_INTERVAL, CONN_REFRESH_PERIOD
from flwr.common.grpc import GRPC_MAX_MESSAGE_LENGTH, create_channel
from flwr.common.logger import log as logger
from flwr.proto.exec_pb2 import StreamLogsRequest # pylint: disable=E0611
from flwr.proto.exec_pb2_grpc import ExecStub

from .utils import init_channel, try_obtain_cli_auth_plugin


def start_stream(
run_id: int, channel: grpc.Channel, refresh_period: int = CONN_REFRESH_PERIOD
Expand Down Expand Up @@ -126,11 +126,6 @@ def print_logs(run_id: int, channel: grpc.Channel, timeout: int) -> None:
logger(DEBUG, "Channel closed")


def on_channel_state_change(channel_connectivity: str) -> None:
"""Log channel connectivity."""
logger(DEBUG, channel_connectivity)


def log(
run_id: Annotated[
int,
Expand Down Expand Up @@ -171,27 +166,18 @@ def log(
)
raise typer.Exit(code=1)

_log_with_exec_api(app, federation_config, run_id, stream)
_log_with_exec_api(app, federation, federation_config, run_id, stream)


def _log_with_exec_api(
app: Path,
federation: str,
federation_config: dict[str, Any],
run_id: int,
stream: bool,
) -> None:

insecure, root_certificates_bytes = validate_certificate_in_federation_config(
app, federation_config
)
channel = create_channel(
server_address=federation_config["address"],
insecure=insecure,
root_certificates=root_certificates_bytes,
max_message_length=GRPC_MAX_MESSAGE_LENGTH,
interceptors=None,
)
channel.subscribe(on_channel_state_change)
auth_plugin = try_obtain_cli_auth_plugin(app, federation, federation_config)
channel = init_channel(app, federation_config, auth_plugin)

if stream:
start_stream(run_id, channel, CONN_REFRESH_PERIOD)
Expand Down
21 changes: 21 additions & 0 deletions src/py/flwr/cli/login/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2024 Flower Labs GmbH. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Flower command line interface `login` command."""

from .login import login as login

__all__ = [
"login",
]
90 changes: 90 additions & 0 deletions src/py/flwr/cli/login/login.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Copyright 2024 Flower Labs GmbH. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Flower command line interface `login` command."""

from pathlib import Path
from typing import Annotated, Optional

import typer

from flwr.cli.config_utils import (
load_and_validate,
validate_federation_in_project_config,
validate_project_config,
)
from flwr.common.constant import AUTH_TYPE
from flwr.proto.exec_pb2 import ( # pylint: disable=E0611
GetLoginDetailsRequest,
GetLoginDetailsResponse,
)
from flwr.proto.exec_pb2_grpc import ExecStub

from ..utils import init_channel, try_obtain_cli_auth_plugin


def login( # pylint: disable=R0914
app: Annotated[
Path,
typer.Argument(help="Path of the Flower App to run."),
] = Path("."),
federation: Annotated[
Optional[str],
typer.Argument(help="Name of the federation to login into."),
] = None,
) -> None:
"""Login to Flower SuperLink."""
typer.secho("Loading project configuration... ", fg=typer.colors.BLUE)

pyproject_path = app / "pyproject.toml" if app else None
config, errors, warnings = load_and_validate(path=pyproject_path)

config = validate_project_config(config, errors, warnings)
federation, federation_config = validate_federation_in_project_config(
federation, config
)

if "address" not in federation_config:
typer.secho(
"❌ `flwr login` currently works with a SuperLink. Ensure that the correct"
"SuperLink (Exec API) address is provided in `pyproject.toml`.",
fg=typer.colors.RED,
bold=True,
)
raise typer.Exit(code=1)

channel = init_channel(app, federation_config, None)
stub = ExecStub(channel)

login_request = GetLoginDetailsRequest()
login_response: GetLoginDetailsResponse = stub.GetLoginDetails(login_request)

# Get the auth plugin
auth_type = login_response.login_details.get(AUTH_TYPE)
auth_plugin = try_obtain_cli_auth_plugin(
app, federation, federation_config, auth_type
)
if auth_plugin is None:
typer.secho(
f'❌ Authentication type "{auth_type}" not found',
fg=typer.colors.RED,
bold=True,
)
raise typer.Exit(code=1)

# Login
auth_config = auth_plugin.login(dict(login_response.login_details), stub)

# Store the tokens
auth_plugin.store_tokens(auth_config)
35 changes: 6 additions & 29 deletions src/py/flwr/cli/ls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@
import io
import json
from datetime import datetime, timedelta
from logging import DEBUG
from pathlib import Path
from typing import Annotated, Any, Optional, Union
from typing import Annotated, Optional, Union

import grpc
import typer
from rich.console import Console
from rich.table import Table
Expand All @@ -31,14 +29,12 @@

from flwr.cli.config_utils import (
load_and_validate,
validate_certificate_in_federation_config,
validate_federation_in_project_config,
validate_project_config,
)
from flwr.common.constant import FAB_CONFIG_FILE, CliOutputFormat, SubStatus
from flwr.common.date import format_timedelta, isoformat8601_utc
from flwr.common.grpc import GRPC_MAX_MESSAGE_LENGTH, create_channel
from flwr.common.logger import log, redirect_output, remove_emojis, restore_output
from flwr.common.logger import redirect_output, remove_emojis, restore_output
from flwr.common.serde import run_from_proto
from flwr.common.typing import Run
from flwr.proto.exec_pb2 import ( # pylint: disable=E0611
Expand All @@ -47,6 +43,8 @@
)
from flwr.proto.exec_pb2_grpc import ExecStub

from .utils import init_channel, try_obtain_cli_auth_plugin

_RunListType = tuple[int, str, str, str, str, str, str, str, str]


Expand Down Expand Up @@ -113,8 +111,8 @@ def ls( # pylint: disable=too-many-locals, too-many-branches
raise ValueError(
"The options '--runs' and '--run-id' are mutually exclusive."
)

channel = _init_channel(app, federation_config)
auth_plugin = try_obtain_cli_auth_plugin(app, federation, federation_config)
channel = init_channel(app, federation_config, auth_plugin)
stub = ExecStub(channel)

# Display information about a specific run ID
Expand Down Expand Up @@ -154,27 +152,6 @@ def ls( # pylint: disable=too-many-locals, too-many-branches
captured_output.close()


def on_channel_state_change(channel_connectivity: str) -> None:
"""Log channel connectivity."""
log(DEBUG, channel_connectivity)


def _init_channel(app: Path, federation_config: dict[str, Any]) -> grpc.Channel:
"""Initialize gRPC channel to the Exec API."""
insecure, root_certificates_bytes = validate_certificate_in_federation_config(
app, federation_config
)
channel = create_channel(
server_address=federation_config["address"],
insecure=insecure,
root_certificates=root_certificates_bytes,
max_message_length=GRPC_MAX_MESSAGE_LENGTH,
interceptors=None,
)
channel.subscribe(on_channel_state_change)
return channel


def _format_runs(run_dict: dict[int, Run], now_isoformat: str) -> list[_RunListType]:
"""Format runs to a list."""

Expand Down
Loading
Loading