flwr 1.13.0__py3-none-any.whl → 1.14.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- flwr/cli/app.py +5 -0
- flwr/cli/build.py +1 -37
- flwr/cli/cli_user_auth_interceptor.py +86 -0
- flwr/cli/config_utils.py +19 -2
- flwr/cli/example.py +1 -0
- flwr/cli/install.py +2 -19
- flwr/cli/log.py +18 -36
- flwr/cli/login/__init__.py +22 -0
- flwr/cli/login/login.py +81 -0
- flwr/cli/ls.py +205 -106
- flwr/cli/new/__init__.py +1 -0
- flwr/cli/new/new.py +25 -14
- flwr/cli/new/templates/app/.gitignore.tpl +3 -0
- flwr/cli/new/templates/app/pyproject.baseline.toml.tpl +1 -1
- flwr/cli/new/templates/app/pyproject.flowertune.toml.tpl +3 -3
- flwr/cli/new/templates/app/pyproject.huggingface.toml.tpl +1 -1
- flwr/cli/new/templates/app/pyproject.jax.toml.tpl +1 -1
- flwr/cli/new/templates/app/pyproject.mlx.toml.tpl +2 -3
- flwr/cli/new/templates/app/pyproject.numpy.toml.tpl +1 -1
- flwr/cli/new/templates/app/pyproject.pytorch.toml.tpl +1 -1
- flwr/cli/new/templates/app/pyproject.sklearn.toml.tpl +1 -1
- flwr/cli/new/templates/app/pyproject.tensorflow.toml.tpl +1 -1
- flwr/cli/run/__init__.py +1 -0
- flwr/cli/run/run.py +89 -39
- flwr/cli/stop.py +130 -0
- flwr/cli/utils.py +172 -8
- flwr/client/app.py +14 -3
- flwr/client/client.py +1 -32
- flwr/client/clientapp/app.py +4 -8
- flwr/client/clientapp/utils.py +1 -0
- flwr/client/grpc_adapter_client/connection.py +1 -1
- flwr/client/grpc_client/connection.py +1 -1
- flwr/client/grpc_rere_client/connection.py +13 -7
- flwr/client/message_handler/message_handler.py +1 -2
- flwr/client/mod/comms_mods.py +1 -0
- flwr/client/mod/localdp_mod.py +1 -1
- flwr/client/nodestate/__init__.py +1 -0
- flwr/client/nodestate/nodestate.py +1 -0
- flwr/client/nodestate/nodestate_factory.py +1 -0
- flwr/client/numpy_client.py +0 -44
- flwr/client/rest_client/connection.py +3 -3
- flwr/client/supernode/app.py +2 -2
- flwr/common/address.py +1 -0
- flwr/common/args.py +1 -0
- flwr/common/auth_plugin/__init__.py +24 -0
- flwr/common/auth_plugin/auth_plugin.py +111 -0
- flwr/common/config.py +3 -1
- flwr/common/constant.py +17 -1
- flwr/common/logger.py +40 -0
- flwr/common/message.py +1 -0
- flwr/common/object_ref.py +57 -54
- flwr/common/pyproject.py +1 -0
- flwr/common/record/__init__.py +1 -0
- flwr/common/record/parametersrecord.py +1 -0
- flwr/common/retry_invoker.py +77 -0
- flwr/common/secure_aggregation/secaggplus_utils.py +2 -2
- flwr/common/telemetry.py +15 -4
- flwr/common/typing.py +12 -0
- flwr/common/version.py +1 -0
- flwr/proto/exec_pb2.py +38 -14
- flwr/proto/exec_pb2.pyi +107 -2
- flwr/proto/exec_pb2_grpc.py +102 -0
- flwr/proto/exec_pb2_grpc.pyi +39 -0
- flwr/proto/fab_pb2.py +4 -4
- flwr/proto/fab_pb2.pyi +4 -1
- flwr/proto/serverappio_pb2.py +18 -18
- flwr/proto/serverappio_pb2.pyi +8 -2
- flwr/proto/serverappio_pb2_grpc.py +34 -0
- flwr/proto/serverappio_pb2_grpc.pyi +13 -0
- flwr/proto/simulationio_pb2.py +2 -2
- flwr/proto/simulationio_pb2_grpc.py +34 -0
- flwr/proto/simulationio_pb2_grpc.pyi +13 -0
- flwr/server/app.py +62 -7
- flwr/server/compat/app_utils.py +7 -1
- flwr/server/driver/grpc_driver.py +11 -63
- flwr/server/driver/inmemory_driver.py +5 -1
- flwr/server/run_serverapp.py +8 -9
- flwr/server/serverapp/app.py +25 -10
- flwr/server/strategy/dpfedavg_fixed.py +1 -0
- flwr/server/superlink/driver/serverappio_grpc.py +1 -0
- flwr/server/superlink/driver/serverappio_servicer.py +82 -23
- flwr/server/superlink/ffs/disk_ffs.py +1 -0
- flwr/server/superlink/fleet/grpc_adapter/grpc_adapter_servicer.py +1 -0
- flwr/server/superlink/fleet/grpc_bidi/flower_service_servicer.py +1 -0
- flwr/server/superlink/fleet/grpc_rere/fleet_servicer.py +32 -12
- flwr/server/superlink/fleet/grpc_rere/server_interceptor.py +12 -11
- flwr/server/superlink/fleet/message_handler/message_handler.py +32 -5
- flwr/server/superlink/fleet/rest_rere/rest_api.py +4 -1
- flwr/server/superlink/fleet/vce/__init__.py +1 -0
- flwr/server/superlink/fleet/vce/backend/__init__.py +1 -0
- flwr/server/superlink/fleet/vce/backend/raybackend.py +1 -0
- flwr/server/superlink/linkstate/in_memory_linkstate.py +21 -30
- flwr/server/superlink/linkstate/linkstate.py +17 -2
- flwr/server/superlink/linkstate/sqlite_linkstate.py +30 -49
- flwr/server/superlink/simulation/simulationio_servicer.py +33 -0
- flwr/server/superlink/utils.py +65 -0
- flwr/simulation/app.py +59 -52
- flwr/simulation/ray_transport/ray_actor.py +1 -0
- flwr/simulation/ray_transport/utils.py +1 -0
- flwr/simulation/run_simulation.py +36 -22
- flwr/simulation/simulationio_connection.py +3 -0
- flwr/superexec/app.py +1 -0
- flwr/superexec/deployment.py +1 -0
- flwr/superexec/exec_grpc.py +19 -1
- flwr/superexec/exec_servicer.py +76 -2
- flwr/superexec/exec_user_auth_interceptor.py +101 -0
- flwr/superexec/executor.py +1 -0
- {flwr-1.13.0.dist-info → flwr-1.14.0.dist-info}/METADATA +8 -8
- {flwr-1.13.0.dist-info → flwr-1.14.0.dist-info}/RECORD +112 -112
- flwr/proto/common_pb2.py +0 -36
- flwr/proto/common_pb2.pyi +0 -121
- flwr/proto/common_pb2_grpc.py +0 -4
- flwr/proto/common_pb2_grpc.pyi +0 -4
- flwr/proto/control_pb2.py +0 -27
- flwr/proto/control_pb2.pyi +0 -7
- flwr/proto/control_pb2_grpc.py +0 -135
- flwr/proto/control_pb2_grpc.pyi +0 -53
- {flwr-1.13.0.dist-info → flwr-1.14.0.dist-info}/LICENSE +0 -0
- {flwr-1.13.0.dist-info → flwr-1.14.0.dist-info}/WHEEL +0 -0
- {flwr-1.13.0.dist-info → flwr-1.14.0.dist-info}/entry_points.txt +0 -0
flwr/cli/app.py
CHANGED
|
@@ -14,15 +14,18 @@
|
|
|
14
14
|
# ==============================================================================
|
|
15
15
|
"""Flower command line interface."""
|
|
16
16
|
|
|
17
|
+
|
|
17
18
|
import typer
|
|
18
19
|
from typer.main import get_command
|
|
19
20
|
|
|
20
21
|
from .build import build
|
|
21
22
|
from .install import install
|
|
22
23
|
from .log import log
|
|
24
|
+
from .login import login
|
|
23
25
|
from .ls import ls
|
|
24
26
|
from .new import new
|
|
25
27
|
from .run import run
|
|
28
|
+
from .stop import stop
|
|
26
29
|
|
|
27
30
|
app = typer.Typer(
|
|
28
31
|
help=typer.style(
|
|
@@ -39,6 +42,8 @@ app.command()(build)
|
|
|
39
42
|
app.command()(install)
|
|
40
43
|
app.command()(log)
|
|
41
44
|
app.command()(ls)
|
|
45
|
+
app.command()(stop)
|
|
46
|
+
app.command()(login)
|
|
42
47
|
|
|
43
48
|
typer_click_object = get_command(app)
|
|
44
49
|
|
flwr/cli/build.py
CHANGED
|
@@ -14,23 +14,20 @@
|
|
|
14
14
|
# ==============================================================================
|
|
15
15
|
"""Flower command line interface `build` command."""
|
|
16
16
|
|
|
17
|
+
|
|
17
18
|
import hashlib
|
|
18
19
|
import os
|
|
19
20
|
import shutil
|
|
20
21
|
import tempfile
|
|
21
22
|
import zipfile
|
|
22
|
-
from logging import DEBUG, ERROR
|
|
23
23
|
from pathlib import Path
|
|
24
24
|
from typing import Annotated, Any, Optional, Union
|
|
25
25
|
|
|
26
26
|
import pathspec
|
|
27
27
|
import tomli_w
|
|
28
28
|
import typer
|
|
29
|
-
from hatchling.builders.wheel import WheelBuilder
|
|
30
|
-
from hatchling.metadata.core import ProjectMetadata
|
|
31
29
|
|
|
32
30
|
from flwr.common.constant import FAB_ALLOWED_EXTENSIONS, FAB_DATE, FAB_HASH_TRUNCATION
|
|
33
|
-
from flwr.common.logger import log
|
|
34
31
|
|
|
35
32
|
from .config_utils import load_and_validate
|
|
36
33
|
from .utils import is_valid_project_name
|
|
@@ -55,27 +52,6 @@ def get_fab_filename(conf: dict[str, Any], fab_hash: str) -> str:
|
|
|
55
52
|
return f"{publisher}.{name}.{version}.{fab_hash_truncated}.fab"
|
|
56
53
|
|
|
57
54
|
|
|
58
|
-
def _build_app_wheel(app: Path) -> Path:
|
|
59
|
-
"""Build app as a wheel and return its path."""
|
|
60
|
-
# Path to your project directory
|
|
61
|
-
app_dir = str(app.resolve())
|
|
62
|
-
try:
|
|
63
|
-
|
|
64
|
-
# Initialize the WheelBuilder
|
|
65
|
-
builder = WheelBuilder(
|
|
66
|
-
app_dir, metadata=ProjectMetadata(root=app_dir, plugin_manager=None)
|
|
67
|
-
)
|
|
68
|
-
|
|
69
|
-
# Build
|
|
70
|
-
whl_path = Path(next(builder.build(directory=app_dir)))
|
|
71
|
-
log(DEBUG, "Wheel succesfully built: %s", str(whl_path))
|
|
72
|
-
except Exception as ex:
|
|
73
|
-
log(ERROR, "Exception encountered when building wheel.", exc_info=ex)
|
|
74
|
-
raise typer.Exit(code=1) from ex
|
|
75
|
-
|
|
76
|
-
return whl_path
|
|
77
|
-
|
|
78
|
-
|
|
79
55
|
# pylint: disable=too-many-locals, too-many-statements
|
|
80
56
|
def build(
|
|
81
57
|
app: Annotated[
|
|
@@ -131,12 +107,6 @@ def build(
|
|
|
131
107
|
bold=True,
|
|
132
108
|
)
|
|
133
109
|
|
|
134
|
-
# Build wheel
|
|
135
|
-
whl_path = _build_app_wheel(app)
|
|
136
|
-
|
|
137
|
-
# Add path to .whl to `[tool.flwr.app]`
|
|
138
|
-
conf["tool"]["flwr"]["app"]["whl"] = str(whl_path.name)
|
|
139
|
-
|
|
140
110
|
# Load .gitignore rules if present
|
|
141
111
|
ignore_spec = _load_gitignore(app)
|
|
142
112
|
|
|
@@ -168,9 +138,6 @@ def build(
|
|
|
168
138
|
and f.name != "pyproject.toml" # Exclude the original pyproject.toml
|
|
169
139
|
]
|
|
170
140
|
|
|
171
|
-
# Include FAB .whl
|
|
172
|
-
all_files.append(whl_path)
|
|
173
|
-
|
|
174
141
|
for file_path in all_files:
|
|
175
142
|
# Read the file content manually
|
|
176
143
|
with open(file_path, "rb") as f:
|
|
@@ -187,9 +154,6 @@ def build(
|
|
|
187
154
|
# Add CONTENT and CONTENT.jwt to the zip file
|
|
188
155
|
write_to_zip(fab_file, ".info/CONTENT", list_file_content)
|
|
189
156
|
|
|
190
|
-
# Erase FAB .whl in app directory
|
|
191
|
-
whl_path.unlink()
|
|
192
|
-
|
|
193
157
|
# Get hash of FAB file
|
|
194
158
|
content = Path(temp_filename).read_bytes()
|
|
195
159
|
fab_hash = hashlib.sha256(content).hexdigest()
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# Copyright 2024 Flower Labs GmbH. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
# ==============================================================================
|
|
15
|
+
"""Flower run interceptor."""
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
from typing import Any, Callable, Union
|
|
19
|
+
|
|
20
|
+
import grpc
|
|
21
|
+
|
|
22
|
+
from flwr.common.auth_plugin import CliAuthPlugin
|
|
23
|
+
from flwr.proto.exec_pb2 import ( # pylint: disable=E0611
|
|
24
|
+
StartRunRequest,
|
|
25
|
+
StreamLogsRequest,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
Request = Union[
|
|
29
|
+
StartRunRequest,
|
|
30
|
+
StreamLogsRequest,
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class CliUserAuthInterceptor(
|
|
35
|
+
grpc.UnaryUnaryClientInterceptor, grpc.UnaryStreamClientInterceptor # type: ignore
|
|
36
|
+
):
|
|
37
|
+
"""CLI interceptor for user authentication."""
|
|
38
|
+
|
|
39
|
+
def __init__(self, auth_plugin: CliAuthPlugin):
|
|
40
|
+
self.auth_plugin = auth_plugin
|
|
41
|
+
|
|
42
|
+
def _authenticated_call(
|
|
43
|
+
self,
|
|
44
|
+
continuation: Callable[[Any, Any], Any],
|
|
45
|
+
client_call_details: grpc.ClientCallDetails,
|
|
46
|
+
request: Request,
|
|
47
|
+
) -> grpc.Call:
|
|
48
|
+
"""Send and receive tokens via metadata."""
|
|
49
|
+
new_metadata = self.auth_plugin.write_tokens_to_metadata(
|
|
50
|
+
client_call_details.metadata or []
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
details = client_call_details._replace(metadata=new_metadata)
|
|
54
|
+
|
|
55
|
+
response = continuation(details, request)
|
|
56
|
+
if response.initial_metadata():
|
|
57
|
+
retrieved_metadata = dict(response.initial_metadata())
|
|
58
|
+
self.auth_plugin.store_tokens(retrieved_metadata)
|
|
59
|
+
|
|
60
|
+
return response
|
|
61
|
+
|
|
62
|
+
def intercept_unary_unary(
|
|
63
|
+
self,
|
|
64
|
+
continuation: Callable[[Any, Any], Any],
|
|
65
|
+
client_call_details: grpc.ClientCallDetails,
|
|
66
|
+
request: Request,
|
|
67
|
+
) -> grpc.Call:
|
|
68
|
+
"""Intercept a unary-unary call for user authentication.
|
|
69
|
+
|
|
70
|
+
This method intercepts a unary-unary RPC call initiated from the CLI and adds
|
|
71
|
+
the required authentication tokens to the RPC metadata.
|
|
72
|
+
"""
|
|
73
|
+
return self._authenticated_call(continuation, client_call_details, request)
|
|
74
|
+
|
|
75
|
+
def intercept_unary_stream(
|
|
76
|
+
self,
|
|
77
|
+
continuation: Callable[[Any, Any], Any],
|
|
78
|
+
client_call_details: grpc.ClientCallDetails,
|
|
79
|
+
request: Request,
|
|
80
|
+
) -> grpc.Call:
|
|
81
|
+
"""Intercept a unary-stream call for user authentication.
|
|
82
|
+
|
|
83
|
+
This method intercepts a unary-stream RPC call initiated from the CLI and adds
|
|
84
|
+
the required authentication tokens to the RPC metadata.
|
|
85
|
+
"""
|
|
86
|
+
return self._authenticated_call(continuation, client_call_details, request)
|
flwr/cli/config_utils.py
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
# ==============================================================================
|
|
15
15
|
"""Utility to validate the `pyproject.toml` file."""
|
|
16
16
|
|
|
17
|
+
|
|
17
18
|
import zipfile
|
|
18
19
|
from io import BytesIO
|
|
19
20
|
from pathlib import Path
|
|
@@ -230,10 +231,14 @@ def load_from_string(toml_content: str) -> Optional[dict[str, Any]]:
|
|
|
230
231
|
return None
|
|
231
232
|
|
|
232
233
|
|
|
233
|
-
def
|
|
234
|
+
def process_loaded_project_config(
|
|
234
235
|
config: Union[dict[str, Any], None], errors: list[str], warnings: list[str]
|
|
235
236
|
) -> dict[str, Any]:
|
|
236
|
-
"""
|
|
237
|
+
"""Process and return the loaded project configuration.
|
|
238
|
+
|
|
239
|
+
This function handles errors and warnings from the `load_and_validate` function,
|
|
240
|
+
exits on critical issues, and returns the validated configuration.
|
|
241
|
+
"""
|
|
237
242
|
if config is None:
|
|
238
243
|
typer.secho(
|
|
239
244
|
"Project configuration could not be loaded.\n"
|
|
@@ -324,3 +329,15 @@ def validate_certificate_in_federation_config(
|
|
|
324
329
|
raise typer.Exit(code=1)
|
|
325
330
|
|
|
326
331
|
return insecure, root_certificates_bytes
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
def exit_if_no_address(federation_config: dict[str, Any], cmd: str) -> None:
|
|
335
|
+
"""Exit if the provided federation_config has no "address" key."""
|
|
336
|
+
if "address" not in federation_config:
|
|
337
|
+
typer.secho(
|
|
338
|
+
f"❌ `flwr {cmd}` currently works with a SuperLink. Ensure that the correct"
|
|
339
|
+
"SuperLink (Exec API) address is provided in `pyproject.toml`.",
|
|
340
|
+
fg=typer.colors.RED,
|
|
341
|
+
bold=True,
|
|
342
|
+
)
|
|
343
|
+
raise typer.Exit(code=1)
|
flwr/cli/example.py
CHANGED
flwr/cli/install.py
CHANGED
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
# ==============================================================================
|
|
15
15
|
"""Flower command line interface `install` command."""
|
|
16
16
|
|
|
17
|
+
|
|
17
18
|
import hashlib
|
|
18
19
|
import shutil
|
|
19
|
-
import subprocess
|
|
20
20
|
import tempfile
|
|
21
21
|
import zipfile
|
|
22
22
|
from io import BytesIO
|
|
@@ -188,25 +188,8 @@ def validate_and_install(
|
|
|
188
188
|
else:
|
|
189
189
|
shutil.copy2(item, install_dir / item.name)
|
|
190
190
|
|
|
191
|
-
whl_file = config["tool"]["flwr"]["app"]["whl"]
|
|
192
|
-
install_whl = install_dir / whl_file
|
|
193
|
-
try:
|
|
194
|
-
subprocess.run(
|
|
195
|
-
["pip", "install", "--no-deps", install_whl],
|
|
196
|
-
capture_output=True,
|
|
197
|
-
text=True,
|
|
198
|
-
check=True,
|
|
199
|
-
)
|
|
200
|
-
except subprocess.CalledProcessError as e:
|
|
201
|
-
typer.secho(
|
|
202
|
-
f"❌ Failed to install {project_name}:\n{e.stderr}",
|
|
203
|
-
fg=typer.colors.RED,
|
|
204
|
-
bold=True,
|
|
205
|
-
)
|
|
206
|
-
raise typer.Exit(code=1) from e
|
|
207
|
-
|
|
208
191
|
typer.secho(
|
|
209
|
-
f"🎊 Successfully installed {project_name}.",
|
|
192
|
+
f"🎊 Successfully installed {project_name} to {install_dir}.",
|
|
210
193
|
fg=typer.colors.GREEN,
|
|
211
194
|
bold=True,
|
|
212
195
|
)
|
flwr/cli/log.py
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
# ==============================================================================
|
|
15
15
|
"""Flower command line interface `log` command."""
|
|
16
16
|
|
|
17
|
+
|
|
17
18
|
import time
|
|
18
19
|
from logging import DEBUG, ERROR, INFO
|
|
19
20
|
from pathlib import Path
|
|
@@ -23,17 +24,18 @@ import grpc
|
|
|
23
24
|
import typer
|
|
24
25
|
|
|
25
26
|
from flwr.cli.config_utils import (
|
|
27
|
+
exit_if_no_address,
|
|
26
28
|
load_and_validate,
|
|
27
|
-
|
|
29
|
+
process_loaded_project_config,
|
|
28
30
|
validate_federation_in_project_config,
|
|
29
|
-
validate_project_config,
|
|
30
31
|
)
|
|
31
32
|
from flwr.common.constant import CONN_RECONNECT_INTERVAL, CONN_REFRESH_PERIOD
|
|
32
|
-
from flwr.common.grpc import GRPC_MAX_MESSAGE_LENGTH, create_channel
|
|
33
33
|
from flwr.common.logger import log as logger
|
|
34
34
|
from flwr.proto.exec_pb2 import StreamLogsRequest # pylint: disable=E0611
|
|
35
35
|
from flwr.proto.exec_pb2_grpc import ExecStub
|
|
36
36
|
|
|
37
|
+
from .utils import init_channel, try_obtain_cli_auth_plugin, unauthenticated_exc_handler
|
|
38
|
+
|
|
37
39
|
|
|
38
40
|
def start_stream(
|
|
39
41
|
run_id: int, channel: grpc.Channel, refresh_period: int = CONN_REFRESH_PERIOD
|
|
@@ -86,8 +88,9 @@ def stream_logs(
|
|
|
86
88
|
latest_timestamp = 0.0
|
|
87
89
|
res = None
|
|
88
90
|
try:
|
|
89
|
-
|
|
90
|
-
|
|
91
|
+
with unauthenticated_exc_handler():
|
|
92
|
+
for res in stub.StreamLogs(req, timeout=duration):
|
|
93
|
+
print(res.log_output, end="")
|
|
91
94
|
except grpc.RpcError as e:
|
|
92
95
|
# pylint: disable=E1101
|
|
93
96
|
if e.code() != grpc.StatusCode.DEADLINE_EXCEEDED:
|
|
@@ -107,9 +110,10 @@ def print_logs(run_id: int, channel: grpc.Channel, timeout: int) -> None:
|
|
|
107
110
|
try:
|
|
108
111
|
while True:
|
|
109
112
|
try:
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
+
with unauthenticated_exc_handler():
|
|
114
|
+
# Enforce timeout for graceful exit
|
|
115
|
+
for res in stub.StreamLogs(req, timeout=timeout):
|
|
116
|
+
print(res.log_output)
|
|
113
117
|
except grpc.RpcError as e:
|
|
114
118
|
# pylint: disable=E1101
|
|
115
119
|
if e.code() == grpc.StatusCode.DEADLINE_EXCEEDED:
|
|
@@ -126,11 +130,6 @@ def print_logs(run_id: int, channel: grpc.Channel, timeout: int) -> None:
|
|
|
126
130
|
logger(DEBUG, "Channel closed")
|
|
127
131
|
|
|
128
132
|
|
|
129
|
-
def on_channel_state_change(channel_connectivity: str) -> None:
|
|
130
|
-
"""Log channel connectivity."""
|
|
131
|
-
logger(DEBUG, channel_connectivity)
|
|
132
|
-
|
|
133
|
-
|
|
134
133
|
def log(
|
|
135
134
|
run_id: Annotated[
|
|
136
135
|
int,
|
|
@@ -157,41 +156,24 @@ def log(
|
|
|
157
156
|
|
|
158
157
|
pyproject_path = app / "pyproject.toml" if app else None
|
|
159
158
|
config, errors, warnings = load_and_validate(path=pyproject_path)
|
|
160
|
-
config =
|
|
159
|
+
config = process_loaded_project_config(config, errors, warnings)
|
|
161
160
|
federation, federation_config = validate_federation_in_project_config(
|
|
162
161
|
federation, config
|
|
163
162
|
)
|
|
163
|
+
exit_if_no_address(federation_config, "log")
|
|
164
164
|
|
|
165
|
-
|
|
166
|
-
typer.secho(
|
|
167
|
-
"❌ `flwr log` currently works with Exec API. Ensure that the correct"
|
|
168
|
-
"Exec API address is provided in the `pyproject.toml`.",
|
|
169
|
-
fg=typer.colors.RED,
|
|
170
|
-
bold=True,
|
|
171
|
-
)
|
|
172
|
-
raise typer.Exit(code=1)
|
|
173
|
-
|
|
174
|
-
_log_with_exec_api(app, federation_config, run_id, stream)
|
|
165
|
+
_log_with_exec_api(app, federation, federation_config, run_id, stream)
|
|
175
166
|
|
|
176
167
|
|
|
177
168
|
def _log_with_exec_api(
|
|
178
169
|
app: Path,
|
|
170
|
+
federation: str,
|
|
179
171
|
federation_config: dict[str, Any],
|
|
180
172
|
run_id: int,
|
|
181
173
|
stream: bool,
|
|
182
174
|
) -> None:
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
app, federation_config
|
|
186
|
-
)
|
|
187
|
-
channel = create_channel(
|
|
188
|
-
server_address=federation_config["address"],
|
|
189
|
-
insecure=insecure,
|
|
190
|
-
root_certificates=root_certificates_bytes,
|
|
191
|
-
max_message_length=GRPC_MAX_MESSAGE_LENGTH,
|
|
192
|
-
interceptors=None,
|
|
193
|
-
)
|
|
194
|
-
channel.subscribe(on_channel_state_change)
|
|
175
|
+
auth_plugin = try_obtain_cli_auth_plugin(app, federation)
|
|
176
|
+
channel = init_channel(app, federation_config, auth_plugin)
|
|
195
177
|
|
|
196
178
|
if stream:
|
|
197
179
|
start_stream(run_id, channel, CONN_REFRESH_PERIOD)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Copyright 2024 Flower Labs GmbH. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
# ==============================================================================
|
|
15
|
+
"""Flower command line interface `login` command."""
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
from .login import login as login
|
|
19
|
+
|
|
20
|
+
__all__ = [
|
|
21
|
+
"login",
|
|
22
|
+
]
|
flwr/cli/login/login.py
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# Copyright 2024 Flower Labs GmbH. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
# ==============================================================================
|
|
15
|
+
"""Flower command line interface `login` command."""
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
from typing import Annotated, Optional
|
|
20
|
+
|
|
21
|
+
import typer
|
|
22
|
+
|
|
23
|
+
from flwr.cli.config_utils import (
|
|
24
|
+
exit_if_no_address,
|
|
25
|
+
load_and_validate,
|
|
26
|
+
process_loaded_project_config,
|
|
27
|
+
validate_federation_in_project_config,
|
|
28
|
+
)
|
|
29
|
+
from flwr.common.constant import AUTH_TYPE
|
|
30
|
+
from flwr.proto.exec_pb2 import ( # pylint: disable=E0611
|
|
31
|
+
GetLoginDetailsRequest,
|
|
32
|
+
GetLoginDetailsResponse,
|
|
33
|
+
)
|
|
34
|
+
from flwr.proto.exec_pb2_grpc import ExecStub
|
|
35
|
+
|
|
36
|
+
from ..utils import init_channel, try_obtain_cli_auth_plugin
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def login( # pylint: disable=R0914
|
|
40
|
+
app: Annotated[
|
|
41
|
+
Path,
|
|
42
|
+
typer.Argument(help="Path of the Flower App to run."),
|
|
43
|
+
] = Path("."),
|
|
44
|
+
federation: Annotated[
|
|
45
|
+
Optional[str],
|
|
46
|
+
typer.Argument(help="Name of the federation to login into."),
|
|
47
|
+
] = None,
|
|
48
|
+
) -> None:
|
|
49
|
+
"""Login to Flower SuperLink."""
|
|
50
|
+
typer.secho("Loading project configuration... ", fg=typer.colors.BLUE)
|
|
51
|
+
|
|
52
|
+
pyproject_path = app / "pyproject.toml" if app else None
|
|
53
|
+
config, errors, warnings = load_and_validate(path=pyproject_path)
|
|
54
|
+
|
|
55
|
+
config = process_loaded_project_config(config, errors, warnings)
|
|
56
|
+
federation, federation_config = validate_federation_in_project_config(
|
|
57
|
+
federation, config
|
|
58
|
+
)
|
|
59
|
+
exit_if_no_address(federation_config, "login")
|
|
60
|
+
channel = init_channel(app, federation_config, None)
|
|
61
|
+
stub = ExecStub(channel)
|
|
62
|
+
|
|
63
|
+
login_request = GetLoginDetailsRequest()
|
|
64
|
+
login_response: GetLoginDetailsResponse = stub.GetLoginDetails(login_request)
|
|
65
|
+
|
|
66
|
+
# Get the auth plugin
|
|
67
|
+
auth_type = login_response.login_details.get(AUTH_TYPE)
|
|
68
|
+
auth_plugin = try_obtain_cli_auth_plugin(app, federation, auth_type)
|
|
69
|
+
if auth_plugin is None:
|
|
70
|
+
typer.secho(
|
|
71
|
+
f'❌ Authentication type "{auth_type}" not found',
|
|
72
|
+
fg=typer.colors.RED,
|
|
73
|
+
bold=True,
|
|
74
|
+
)
|
|
75
|
+
raise typer.Exit(code=1)
|
|
76
|
+
|
|
77
|
+
# Login
|
|
78
|
+
auth_config = auth_plugin.login(dict(login_response.login_details), stub)
|
|
79
|
+
|
|
80
|
+
# Store the tokens
|
|
81
|
+
auth_plugin.store_tokens(auth_config)
|