flwr 1.14.0__py3-none-any.whl → 1.15.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/auth_plugin/__init__.py +31 -0
- flwr/cli/auth_plugin/oidc_cli_plugin.py +150 -0
- flwr/cli/cli_user_auth_interceptor.py +6 -2
- flwr/cli/config_utils.py +24 -147
- flwr/cli/constant.py +27 -0
- flwr/cli/install.py +1 -1
- flwr/cli/log.py +18 -3
- flwr/cli/login/login.py +43 -8
- flwr/cli/ls.py +14 -5
- flwr/cli/new/templates/app/README.md.tpl +3 -2
- flwr/cli/new/templates/app/pyproject.baseline.toml.tpl +4 -4
- flwr/cli/new/templates/app/pyproject.flowertune.toml.tpl +2 -2
- flwr/cli/new/templates/app/pyproject.huggingface.toml.tpl +4 -4
- flwr/cli/new/templates/app/pyproject.jax.toml.tpl +2 -2
- flwr/cli/new/templates/app/pyproject.mlx.toml.tpl +2 -2
- flwr/cli/new/templates/app/pyproject.numpy.toml.tpl +2 -2
- flwr/cli/new/templates/app/pyproject.pytorch.toml.tpl +4 -4
- flwr/cli/new/templates/app/pyproject.sklearn.toml.tpl +3 -3
- flwr/cli/new/templates/app/pyproject.tensorflow.toml.tpl +2 -2
- flwr/cli/run/run.py +21 -11
- flwr/cli/stop.py +13 -4
- flwr/cli/utils.py +54 -40
- flwr/client/app.py +36 -48
- flwr/client/clientapp/app.py +19 -25
- flwr/client/clientapp/utils.py +1 -1
- flwr/client/grpc_client/connection.py +1 -12
- flwr/client/grpc_rere_client/client_interceptor.py +19 -119
- flwr/client/grpc_rere_client/connection.py +46 -36
- flwr/client/grpc_rere_client/grpc_adapter.py +12 -12
- flwr/client/message_handler/task_handler.py +0 -17
- flwr/client/rest_client/connection.py +34 -26
- flwr/client/supernode/app.py +18 -72
- flwr/common/args.py +25 -47
- flwr/common/auth_plugin/auth_plugin.py +34 -23
- flwr/common/config.py +166 -16
- flwr/common/constant.py +22 -9
- flwr/common/differential_privacy.py +2 -1
- flwr/common/exit/__init__.py +24 -0
- flwr/common/exit/exit.py +99 -0
- flwr/common/exit/exit_code.py +93 -0
- flwr/common/exit_handlers.py +24 -10
- flwr/common/grpc.py +167 -4
- flwr/common/logger.py +26 -7
- flwr/common/record/recordset.py +1 -1
- flwr/common/secure_aggregation/crypto/symmetric_encryption.py +45 -0
- flwr/common/serde.py +6 -4
- flwr/common/typing.py +20 -0
- flwr/proto/clientappio_pb2.py +1 -1
- flwr/proto/error_pb2.py +1 -1
- flwr/proto/exec_pb2.py +13 -25
- flwr/proto/exec_pb2.pyi +27 -54
- flwr/proto/fab_pb2.py +1 -1
- flwr/proto/fleet_pb2.py +31 -31
- flwr/proto/fleet_pb2.pyi +23 -23
- flwr/proto/fleet_pb2_grpc.py +30 -30
- flwr/proto/fleet_pb2_grpc.pyi +20 -20
- flwr/proto/grpcadapter_pb2.py +1 -1
- flwr/proto/log_pb2.py +1 -1
- flwr/proto/message_pb2.py +1 -1
- flwr/proto/node_pb2.py +3 -3
- flwr/proto/node_pb2.pyi +1 -4
- flwr/proto/recordset_pb2.py +1 -1
- flwr/proto/run_pb2.py +1 -1
- flwr/proto/serverappio_pb2.py +24 -25
- flwr/proto/serverappio_pb2.pyi +26 -32
- flwr/proto/serverappio_pb2_grpc.py +28 -28
- flwr/proto/serverappio_pb2_grpc.pyi +16 -16
- flwr/proto/simulationio_pb2.py +1 -1
- flwr/proto/task_pb2.py +1 -1
- flwr/proto/transport_pb2.py +1 -1
- flwr/server/app.py +116 -128
- flwr/server/compat/app_utils.py +0 -1
- flwr/server/compat/driver_client_proxy.py +1 -2
- flwr/server/driver/grpc_driver.py +32 -27
- flwr/server/driver/inmemory_driver.py +2 -1
- flwr/server/serverapp/app.py +12 -10
- flwr/server/superlink/driver/serverappio_grpc.py +1 -1
- flwr/server/superlink/driver/serverappio_servicer.py +74 -48
- flwr/server/superlink/fleet/grpc_adapter/grpc_adapter_servicer.py +20 -88
- flwr/server/superlink/fleet/grpc_bidi/grpc_server.py +2 -165
- flwr/server/superlink/fleet/grpc_rere/fleet_servicer.py +25 -24
- flwr/server/superlink/fleet/grpc_rere/server_interceptor.py +97 -168
- flwr/server/superlink/fleet/message_handler/message_handler.py +37 -24
- flwr/server/superlink/fleet/rest_rere/rest_api.py +16 -18
- flwr/server/superlink/fleet/vce/vce_api.py +2 -2
- flwr/server/superlink/linkstate/in_memory_linkstate.py +45 -75
- flwr/server/superlink/linkstate/linkstate.py +17 -38
- flwr/server/superlink/linkstate/sqlite_linkstate.py +81 -145
- flwr/server/superlink/linkstate/utils.py +18 -8
- flwr/server/superlink/simulation/simulationio_grpc.py +1 -1
- flwr/server/utils/validator.py +9 -34
- flwr/simulation/app.py +4 -6
- flwr/simulation/legacy_app.py +4 -2
- flwr/simulation/run_simulation.py +1 -1
- flwr/simulation/simulationio_connection.py +2 -1
- flwr/superexec/exec_grpc.py +1 -1
- flwr/superexec/exec_servicer.py +23 -2
- {flwr-1.14.0.dist-info → flwr-1.15.0.dist-info}/METADATA +8 -8
- {flwr-1.14.0.dist-info → flwr-1.15.0.dist-info}/RECORD +102 -96
- {flwr-1.14.0.dist-info → flwr-1.15.0.dist-info}/LICENSE +0 -0
- {flwr-1.14.0.dist-info → flwr-1.15.0.dist-info}/WHEEL +0 -0
- {flwr-1.14.0.dist-info → flwr-1.15.0.dist-info}/entry_points.txt +0 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Copyright 2025 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 user auth plugins."""
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
from flwr.common.auth_plugin import CliAuthPlugin
|
|
19
|
+
from flwr.common.constant import AuthType
|
|
20
|
+
|
|
21
|
+
from .oidc_cli_plugin import OidcCliPlugin
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def get_cli_auth_plugins() -> dict[str, type[CliAuthPlugin]]:
|
|
25
|
+
"""Return all CLI authentication plugins."""
|
|
26
|
+
return {AuthType.OIDC: OidcCliPlugin}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
__all__ = [
|
|
30
|
+
"get_cli_auth_plugins",
|
|
31
|
+
]
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
# Copyright 2025 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 CLI user auth plugin for OIDC."""
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
import json
|
|
19
|
+
import time
|
|
20
|
+
from collections.abc import Sequence
|
|
21
|
+
from pathlib import Path
|
|
22
|
+
from typing import Any, Optional, Union
|
|
23
|
+
|
|
24
|
+
import typer
|
|
25
|
+
|
|
26
|
+
from flwr.common.auth_plugin import CliAuthPlugin
|
|
27
|
+
from flwr.common.constant import (
|
|
28
|
+
ACCESS_TOKEN_KEY,
|
|
29
|
+
AUTH_TYPE_KEY,
|
|
30
|
+
REFRESH_TOKEN_KEY,
|
|
31
|
+
AuthType,
|
|
32
|
+
)
|
|
33
|
+
from flwr.common.typing import UserAuthCredentials, UserAuthLoginDetails
|
|
34
|
+
from flwr.proto.exec_pb2 import ( # pylint: disable=E0611
|
|
35
|
+
GetAuthTokensRequest,
|
|
36
|
+
GetAuthTokensResponse,
|
|
37
|
+
)
|
|
38
|
+
from flwr.proto.exec_pb2_grpc import ExecStub
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class OidcCliPlugin(CliAuthPlugin):
|
|
42
|
+
"""Flower OIDC auth plugin for CLI."""
|
|
43
|
+
|
|
44
|
+
def __init__(self, credentials_path: Path):
|
|
45
|
+
self.access_token: Optional[str] = None
|
|
46
|
+
self.refresh_token: Optional[str] = None
|
|
47
|
+
self.credentials_path = credentials_path
|
|
48
|
+
|
|
49
|
+
@staticmethod
|
|
50
|
+
def login(
|
|
51
|
+
login_details: UserAuthLoginDetails,
|
|
52
|
+
exec_stub: ExecStub,
|
|
53
|
+
) -> UserAuthCredentials:
|
|
54
|
+
"""Authenticate the user and retrieve authentication credentials."""
|
|
55
|
+
typer.secho(
|
|
56
|
+
"Please login with your user credentials here: "
|
|
57
|
+
f"{login_details.verification_uri_complete}",
|
|
58
|
+
fg=typer.colors.BLUE,
|
|
59
|
+
)
|
|
60
|
+
start_time = time.time()
|
|
61
|
+
time.sleep(login_details.interval)
|
|
62
|
+
|
|
63
|
+
while (time.time() - start_time) < login_details.expires_in:
|
|
64
|
+
res: GetAuthTokensResponse = exec_stub.GetAuthTokens(
|
|
65
|
+
GetAuthTokensRequest(device_code=login_details.device_code)
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
access_token = res.access_token
|
|
69
|
+
refresh_token = res.refresh_token
|
|
70
|
+
|
|
71
|
+
if access_token and refresh_token:
|
|
72
|
+
typer.secho(
|
|
73
|
+
"✅ Login successful.",
|
|
74
|
+
fg=typer.colors.GREEN,
|
|
75
|
+
bold=False,
|
|
76
|
+
)
|
|
77
|
+
return UserAuthCredentials(
|
|
78
|
+
access_token=access_token,
|
|
79
|
+
refresh_token=refresh_token,
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
time.sleep(login_details.interval)
|
|
83
|
+
|
|
84
|
+
typer.secho(
|
|
85
|
+
"❌ Timeout, failed to sign in.",
|
|
86
|
+
fg=typer.colors.RED,
|
|
87
|
+
bold=True,
|
|
88
|
+
)
|
|
89
|
+
raise typer.Exit(code=1)
|
|
90
|
+
|
|
91
|
+
def store_tokens(self, credentials: UserAuthCredentials) -> None:
|
|
92
|
+
"""Store authentication tokens to the `credentials_path`.
|
|
93
|
+
|
|
94
|
+
The credentials, including tokens, will be saved as a JSON file
|
|
95
|
+
at `credentials_path`.
|
|
96
|
+
"""
|
|
97
|
+
self.access_token = credentials.access_token
|
|
98
|
+
self.refresh_token = credentials.refresh_token
|
|
99
|
+
json_dict = {
|
|
100
|
+
AUTH_TYPE_KEY: AuthType.OIDC,
|
|
101
|
+
ACCESS_TOKEN_KEY: credentials.access_token,
|
|
102
|
+
REFRESH_TOKEN_KEY: credentials.refresh_token,
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
with open(self.credentials_path, "w", encoding="utf-8") as file:
|
|
106
|
+
json.dump(json_dict, file, indent=4)
|
|
107
|
+
|
|
108
|
+
def load_tokens(self) -> None:
|
|
109
|
+
"""Load authentication tokens from the `credentials_path`."""
|
|
110
|
+
with open(self.credentials_path, encoding="utf-8") as file:
|
|
111
|
+
json_dict: dict[str, Any] = json.load(file)
|
|
112
|
+
access_token = json_dict.get(ACCESS_TOKEN_KEY)
|
|
113
|
+
refresh_token = json_dict.get(REFRESH_TOKEN_KEY)
|
|
114
|
+
|
|
115
|
+
if isinstance(access_token, str) and isinstance(refresh_token, str):
|
|
116
|
+
self.access_token = access_token
|
|
117
|
+
self.refresh_token = refresh_token
|
|
118
|
+
|
|
119
|
+
def write_tokens_to_metadata(
|
|
120
|
+
self, metadata: Sequence[tuple[str, Union[str, bytes]]]
|
|
121
|
+
) -> Sequence[tuple[str, Union[str, bytes]]]:
|
|
122
|
+
"""Write authentication tokens to the provided metadata."""
|
|
123
|
+
if self.access_token is None or self.refresh_token is None:
|
|
124
|
+
typer.secho(
|
|
125
|
+
"❌ Missing authentication tokens. Please login first.",
|
|
126
|
+
fg=typer.colors.RED,
|
|
127
|
+
bold=True,
|
|
128
|
+
)
|
|
129
|
+
raise typer.Exit(code=1)
|
|
130
|
+
|
|
131
|
+
return list(metadata) + [
|
|
132
|
+
(ACCESS_TOKEN_KEY, self.access_token),
|
|
133
|
+
(REFRESH_TOKEN_KEY, self.refresh_token),
|
|
134
|
+
]
|
|
135
|
+
|
|
136
|
+
def read_tokens_from_metadata(
|
|
137
|
+
self, metadata: Sequence[tuple[str, Union[str, bytes]]]
|
|
138
|
+
) -> Optional[UserAuthCredentials]:
|
|
139
|
+
"""Read authentication tokens from the provided metadata."""
|
|
140
|
+
metadata_dict = dict(metadata)
|
|
141
|
+
access_token = metadata_dict.get(ACCESS_TOKEN_KEY)
|
|
142
|
+
refresh_token = metadata_dict.get(REFRESH_TOKEN_KEY)
|
|
143
|
+
|
|
144
|
+
if isinstance(access_token, str) and isinstance(refresh_token, str):
|
|
145
|
+
return UserAuthCredentials(
|
|
146
|
+
access_token=access_token,
|
|
147
|
+
refresh_token=refresh_token,
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
return None
|
|
@@ -54,8 +54,12 @@ class CliUserAuthInterceptor(
|
|
|
54
54
|
|
|
55
55
|
response = continuation(details, request)
|
|
56
56
|
if response.initial_metadata():
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
credentials = self.auth_plugin.read_tokens_from_metadata(
|
|
58
|
+
response.initial_metadata()
|
|
59
|
+
)
|
|
60
|
+
# The metadata contains tokens only if they have been refreshed
|
|
61
|
+
if credentials is not None:
|
|
62
|
+
self.auth_plugin.store_tokens(credentials)
|
|
59
63
|
|
|
60
64
|
return response
|
|
61
65
|
|
flwr/cli/config_utils.py
CHANGED
|
@@ -15,53 +15,19 @@
|
|
|
15
15
|
"""Utility to validate the `pyproject.toml` file."""
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
import zipfile
|
|
19
|
-
from io import BytesIO
|
|
20
18
|
from pathlib import Path
|
|
21
|
-
from typing import
|
|
19
|
+
from typing import Any, Optional, Union
|
|
22
20
|
|
|
23
21
|
import tomli
|
|
24
22
|
import typer
|
|
25
23
|
|
|
26
|
-
from flwr.common import
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
Parameters
|
|
34
|
-
----------
|
|
35
|
-
fab_file : Union[Path, bytes]
|
|
36
|
-
The Flower App Bundle file to validate and extract the metadata from.
|
|
37
|
-
It can either be a path to the file or the file itself as bytes.
|
|
38
|
-
|
|
39
|
-
Returns
|
|
40
|
-
-------
|
|
41
|
-
Dict[str, Any]
|
|
42
|
-
The `config` of the given Flower App Bundle.
|
|
43
|
-
"""
|
|
44
|
-
fab_file_archive: Union[Path, IO[bytes]]
|
|
45
|
-
if isinstance(fab_file, bytes):
|
|
46
|
-
fab_file_archive = BytesIO(fab_file)
|
|
47
|
-
elif isinstance(fab_file, Path):
|
|
48
|
-
fab_file_archive = fab_file
|
|
49
|
-
else:
|
|
50
|
-
raise ValueError("fab_file must be either a Path or bytes")
|
|
51
|
-
|
|
52
|
-
with zipfile.ZipFile(fab_file_archive, "r") as zipf:
|
|
53
|
-
with zipf.open("pyproject.toml") as file:
|
|
54
|
-
toml_content = file.read().decode("utf-8")
|
|
55
|
-
|
|
56
|
-
conf = load_from_string(toml_content)
|
|
57
|
-
if conf is None:
|
|
58
|
-
raise ValueError("Invalid TOML content in pyproject.toml")
|
|
59
|
-
|
|
60
|
-
is_valid, errors, _ = validate(conf, check_module=False)
|
|
61
|
-
if not is_valid:
|
|
62
|
-
raise ValueError(errors)
|
|
63
|
-
|
|
64
|
-
return conf
|
|
24
|
+
from flwr.common.config import (
|
|
25
|
+
fuse_dicts,
|
|
26
|
+
get_fab_config,
|
|
27
|
+
get_metadata_from_config,
|
|
28
|
+
parse_config_args,
|
|
29
|
+
validate_config,
|
|
30
|
+
)
|
|
65
31
|
|
|
66
32
|
|
|
67
33
|
def get_fab_metadata(fab_file: Union[Path, bytes]) -> tuple[str, str]:
|
|
@@ -78,12 +44,7 @@ def get_fab_metadata(fab_file: Union[Path, bytes]) -> tuple[str, str]:
|
|
|
78
44
|
Tuple[str, str]
|
|
79
45
|
The `fab_id` and `fab_version` of the given Flower App Bundle.
|
|
80
46
|
"""
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
return (
|
|
84
|
-
f"{conf['tool']['flwr']['app']['publisher']}/{conf['project']['name']}",
|
|
85
|
-
conf["project"]["version"],
|
|
86
|
-
)
|
|
47
|
+
return get_metadata_from_config(get_fab_config(fab_file))
|
|
87
48
|
|
|
88
49
|
|
|
89
50
|
def load_and_validate(
|
|
@@ -120,7 +81,7 @@ def load_and_validate(
|
|
|
120
81
|
]
|
|
121
82
|
return (None, errors, [])
|
|
122
83
|
|
|
123
|
-
is_valid, errors, warnings =
|
|
84
|
+
is_valid, errors, warnings = validate_config(config, check_module, path.parent)
|
|
124
85
|
|
|
125
86
|
if not is_valid:
|
|
126
87
|
return (None, errors, warnings)
|
|
@@ -133,102 +94,11 @@ def load(toml_path: Path) -> Optional[dict[str, Any]]:
|
|
|
133
94
|
if not toml_path.is_file():
|
|
134
95
|
return None
|
|
135
96
|
|
|
136
|
-
with toml_path.open(
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
for key, value in config_dict.items():
|
|
142
|
-
if isinstance(value, dict):
|
|
143
|
-
_validate_run_config(config_dict[key], errors)
|
|
144
|
-
elif not isinstance(value, get_args(UserConfigValue)):
|
|
145
|
-
raise ValueError(
|
|
146
|
-
f"The value for key {key} needs to be of type `int`, `float`, "
|
|
147
|
-
"`bool, `str`, or a `dict` of those.",
|
|
148
|
-
)
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
# pylint: disable=too-many-branches
|
|
152
|
-
def validate_fields(config: dict[str, Any]) -> tuple[bool, list[str], list[str]]:
|
|
153
|
-
"""Validate pyproject.toml fields."""
|
|
154
|
-
errors = []
|
|
155
|
-
warnings = []
|
|
156
|
-
|
|
157
|
-
if "project" not in config:
|
|
158
|
-
errors.append("Missing [project] section")
|
|
159
|
-
else:
|
|
160
|
-
if "name" not in config["project"]:
|
|
161
|
-
errors.append('Property "name" missing in [project]')
|
|
162
|
-
if "version" not in config["project"]:
|
|
163
|
-
errors.append('Property "version" missing in [project]')
|
|
164
|
-
if "description" not in config["project"]:
|
|
165
|
-
warnings.append('Recommended property "description" missing in [project]')
|
|
166
|
-
if "license" not in config["project"]:
|
|
167
|
-
warnings.append('Recommended property "license" missing in [project]')
|
|
168
|
-
if "authors" not in config["project"]:
|
|
169
|
-
warnings.append('Recommended property "authors" missing in [project]')
|
|
170
|
-
|
|
171
|
-
if (
|
|
172
|
-
"tool" not in config
|
|
173
|
-
or "flwr" not in config["tool"]
|
|
174
|
-
or "app" not in config["tool"]["flwr"]
|
|
175
|
-
):
|
|
176
|
-
errors.append("Missing [tool.flwr.app] section")
|
|
177
|
-
else:
|
|
178
|
-
if "publisher" not in config["tool"]["flwr"]["app"]:
|
|
179
|
-
errors.append('Property "publisher" missing in [tool.flwr.app]')
|
|
180
|
-
if "config" in config["tool"]["flwr"]["app"]:
|
|
181
|
-
_validate_run_config(config["tool"]["flwr"]["app"]["config"], errors)
|
|
182
|
-
if "components" not in config["tool"]["flwr"]["app"]:
|
|
183
|
-
errors.append("Missing [tool.flwr.app.components] section")
|
|
184
|
-
else:
|
|
185
|
-
if "serverapp" not in config["tool"]["flwr"]["app"]["components"]:
|
|
186
|
-
errors.append(
|
|
187
|
-
'Property "serverapp" missing in [tool.flwr.app.components]'
|
|
188
|
-
)
|
|
189
|
-
if "clientapp" not in config["tool"]["flwr"]["app"]["components"]:
|
|
190
|
-
errors.append(
|
|
191
|
-
'Property "clientapp" missing in [tool.flwr.app.components]'
|
|
192
|
-
)
|
|
193
|
-
|
|
194
|
-
return len(errors) == 0, errors, warnings
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
def validate(
|
|
198
|
-
config: dict[str, Any],
|
|
199
|
-
check_module: bool = True,
|
|
200
|
-
project_dir: Optional[Union[str, Path]] = None,
|
|
201
|
-
) -> tuple[bool, list[str], list[str]]:
|
|
202
|
-
"""Validate pyproject.toml."""
|
|
203
|
-
is_valid, errors, warnings = validate_fields(config)
|
|
204
|
-
|
|
205
|
-
if not is_valid:
|
|
206
|
-
return False, errors, warnings
|
|
207
|
-
|
|
208
|
-
# Validate serverapp
|
|
209
|
-
serverapp_ref = config["tool"]["flwr"]["app"]["components"]["serverapp"]
|
|
210
|
-
is_valid, reason = object_ref.validate(serverapp_ref, check_module, project_dir)
|
|
211
|
-
|
|
212
|
-
if not is_valid and isinstance(reason, str):
|
|
213
|
-
return False, [reason], []
|
|
214
|
-
|
|
215
|
-
# Validate clientapp
|
|
216
|
-
clientapp_ref = config["tool"]["flwr"]["app"]["components"]["clientapp"]
|
|
217
|
-
is_valid, reason = object_ref.validate(clientapp_ref, check_module, project_dir)
|
|
218
|
-
|
|
219
|
-
if not is_valid and isinstance(reason, str):
|
|
220
|
-
return False, [reason], []
|
|
221
|
-
|
|
222
|
-
return True, [], []
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
def load_from_string(toml_content: str) -> Optional[dict[str, Any]]:
|
|
226
|
-
"""Load TOML content from a string and return as dict."""
|
|
227
|
-
try:
|
|
228
|
-
data = tomli.loads(toml_content)
|
|
229
|
-
return data
|
|
230
|
-
except tomli.TOMLDecodeError:
|
|
231
|
-
return None
|
|
97
|
+
with toml_path.open("rb") as toml_file:
|
|
98
|
+
try:
|
|
99
|
+
return tomli.load(toml_file)
|
|
100
|
+
except tomli.TOMLDecodeError:
|
|
101
|
+
return None
|
|
232
102
|
|
|
233
103
|
|
|
234
104
|
def process_loaded_project_config(
|
|
@@ -263,7 +133,9 @@ def process_loaded_project_config(
|
|
|
263
133
|
|
|
264
134
|
|
|
265
135
|
def validate_federation_in_project_config(
|
|
266
|
-
federation: Optional[str],
|
|
136
|
+
federation: Optional[str],
|
|
137
|
+
config: dict[str, Any],
|
|
138
|
+
overrides: Optional[list[str]] = None,
|
|
267
139
|
) -> tuple[str, dict[str, Any]]:
|
|
268
140
|
"""Validate the federation name in the Flower project configuration."""
|
|
269
141
|
federation = federation or config["tool"]["flwr"]["federations"].get("default")
|
|
@@ -293,6 +165,11 @@ def validate_federation_in_project_config(
|
|
|
293
165
|
)
|
|
294
166
|
raise typer.Exit(code=1)
|
|
295
167
|
|
|
168
|
+
# Override the federation configuration if provided
|
|
169
|
+
if overrides:
|
|
170
|
+
overrides_dict = parse_config_args(overrides, flatten=False)
|
|
171
|
+
federation_config = fuse_dicts(federation_config, overrides_dict)
|
|
172
|
+
|
|
296
173
|
return federation, federation_config
|
|
297
174
|
|
|
298
175
|
|
|
@@ -305,7 +182,7 @@ def validate_certificate_in_federation_config(
|
|
|
305
182
|
root_certificates_bytes = (app / root_certificates).read_bytes()
|
|
306
183
|
if insecure := bool(insecure_str):
|
|
307
184
|
typer.secho(
|
|
308
|
-
"❌ `
|
|
185
|
+
"❌ `root-certificates` were provided but the `insecure` parameter "
|
|
309
186
|
"is set to `True`.",
|
|
310
187
|
fg=typer.colors.RED,
|
|
311
188
|
bold=True,
|
flwr/cli/constant.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Copyright 2025 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
|
+
"""Constants for CLI commands."""
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
# The help message for `--federation-config` option
|
|
19
|
+
FEDERATION_CONFIG_HELP_MESSAGE = (
|
|
20
|
+
"Override federation configuration values in the format:\n\n"
|
|
21
|
+
"`--federation-config 'key1=value1 key2=value2' --federation-config "
|
|
22
|
+
"'key3=value3'`\n\nValues can be of any type supported in TOML, such as "
|
|
23
|
+
"bool, int, float, or string. Ensure that the keys (`key1`, `key2`, `key3` "
|
|
24
|
+
"in this example) exist in the federation configuration under the "
|
|
25
|
+
"`[tool.flwr.federations.<YOUR_FEDERATION>]` table of the `pyproject.toml` "
|
|
26
|
+
"for proper overriding."
|
|
27
|
+
)
|
flwr/cli/install.py
CHANGED
|
@@ -154,7 +154,7 @@ def validate_and_install(
|
|
|
154
154
|
)
|
|
155
155
|
raise typer.Exit(code=1)
|
|
156
156
|
|
|
157
|
-
|
|
157
|
+
fab_id, version = get_metadata_from_config(config)
|
|
158
158
|
publisher, project_name = fab_id.split("/")
|
|
159
159
|
config_metadata = (publisher, project_name, version, fab_hash)
|
|
160
160
|
|
flwr/cli/log.py
CHANGED
|
@@ -29,6 +29,7 @@ from flwr.cli.config_utils import (
|
|
|
29
29
|
process_loaded_project_config,
|
|
30
30
|
validate_federation_in_project_config,
|
|
31
31
|
)
|
|
32
|
+
from flwr.cli.constant import FEDERATION_CONFIG_HELP_MESSAGE
|
|
32
33
|
from flwr.common.constant import CONN_RECONNECT_INTERVAL, CONN_REFRESH_PERIOD
|
|
33
34
|
from flwr.common.logger import log as logger
|
|
34
35
|
from flwr.proto.exec_pb2 import StreamLogsRequest # pylint: disable=E0611
|
|
@@ -57,6 +58,8 @@ def start_stream(
|
|
|
57
58
|
logger(ERROR, "Invalid run_id `%s`, exiting", run_id)
|
|
58
59
|
if e.code() == grpc.StatusCode.CANCELLED:
|
|
59
60
|
pass
|
|
61
|
+
else:
|
|
62
|
+
raise e
|
|
60
63
|
finally:
|
|
61
64
|
channel.close()
|
|
62
65
|
|
|
@@ -123,6 +126,7 @@ def print_logs(run_id: int, channel: grpc.Channel, timeout: int) -> None:
|
|
|
123
126
|
break
|
|
124
127
|
if e.code() == grpc.StatusCode.CANCELLED:
|
|
125
128
|
break
|
|
129
|
+
raise e
|
|
126
130
|
except KeyboardInterrupt:
|
|
127
131
|
logger(DEBUG, "Stream interrupted by user")
|
|
128
132
|
finally:
|
|
@@ -143,6 +147,13 @@ def log(
|
|
|
143
147
|
Optional[str],
|
|
144
148
|
typer.Argument(help="Name of the federation to run the app on"),
|
|
145
149
|
] = None,
|
|
150
|
+
federation_config_overrides: Annotated[
|
|
151
|
+
Optional[list[str]],
|
|
152
|
+
typer.Option(
|
|
153
|
+
"--federation-config",
|
|
154
|
+
help=FEDERATION_CONFIG_HELP_MESSAGE,
|
|
155
|
+
),
|
|
156
|
+
] = None,
|
|
146
157
|
stream: Annotated[
|
|
147
158
|
bool,
|
|
148
159
|
typer.Option(
|
|
@@ -158,11 +169,15 @@ def log(
|
|
|
158
169
|
config, errors, warnings = load_and_validate(path=pyproject_path)
|
|
159
170
|
config = process_loaded_project_config(config, errors, warnings)
|
|
160
171
|
federation, federation_config = validate_federation_in_project_config(
|
|
161
|
-
federation, config
|
|
172
|
+
federation, config, federation_config_overrides
|
|
162
173
|
)
|
|
163
174
|
exit_if_no_address(federation_config, "log")
|
|
164
175
|
|
|
165
|
-
|
|
176
|
+
try:
|
|
177
|
+
_log_with_exec_api(app, federation, federation_config, run_id, stream)
|
|
178
|
+
except Exception as err: # pylint: disable=broad-except
|
|
179
|
+
typer.secho(str(err), fg=typer.colors.RED, bold=True)
|
|
180
|
+
raise typer.Exit(code=1) from None
|
|
166
181
|
|
|
167
182
|
|
|
168
183
|
def _log_with_exec_api(
|
|
@@ -172,7 +187,7 @@ def _log_with_exec_api(
|
|
|
172
187
|
run_id: int,
|
|
173
188
|
stream: bool,
|
|
174
189
|
) -> None:
|
|
175
|
-
auth_plugin = try_obtain_cli_auth_plugin(app, federation)
|
|
190
|
+
auth_plugin = try_obtain_cli_auth_plugin(app, federation, federation_config)
|
|
176
191
|
channel = init_channel(app, federation_config, auth_plugin)
|
|
177
192
|
|
|
178
193
|
if stream:
|
flwr/cli/login/login.py
CHANGED
|
@@ -26,14 +26,19 @@ from flwr.cli.config_utils import (
|
|
|
26
26
|
process_loaded_project_config,
|
|
27
27
|
validate_federation_in_project_config,
|
|
28
28
|
)
|
|
29
|
-
from flwr.
|
|
29
|
+
from flwr.cli.constant import FEDERATION_CONFIG_HELP_MESSAGE
|
|
30
|
+
from flwr.common.typing import UserAuthLoginDetails
|
|
30
31
|
from flwr.proto.exec_pb2 import ( # pylint: disable=E0611
|
|
31
32
|
GetLoginDetailsRequest,
|
|
32
33
|
GetLoginDetailsResponse,
|
|
33
34
|
)
|
|
34
35
|
from flwr.proto.exec_pb2_grpc import ExecStub
|
|
35
36
|
|
|
36
|
-
from ..utils import
|
|
37
|
+
from ..utils import (
|
|
38
|
+
init_channel,
|
|
39
|
+
try_obtain_cli_auth_plugin,
|
|
40
|
+
unauthenticated_exc_handler,
|
|
41
|
+
)
|
|
37
42
|
|
|
38
43
|
|
|
39
44
|
def login( # pylint: disable=R0914
|
|
@@ -45,6 +50,13 @@ def login( # pylint: disable=R0914
|
|
|
45
50
|
Optional[str],
|
|
46
51
|
typer.Argument(help="Name of the federation to login into."),
|
|
47
52
|
] = None,
|
|
53
|
+
federation_config_overrides: Annotated[
|
|
54
|
+
Optional[list[str]],
|
|
55
|
+
typer.Option(
|
|
56
|
+
"--federation-config",
|
|
57
|
+
help=FEDERATION_CONFIG_HELP_MESSAGE,
|
|
58
|
+
),
|
|
59
|
+
] = None,
|
|
48
60
|
) -> None:
|
|
49
61
|
"""Login to Flower SuperLink."""
|
|
50
62
|
typer.secho("Loading project configuration... ", fg=typer.colors.BLUE)
|
|
@@ -54,18 +66,33 @@ def login( # pylint: disable=R0914
|
|
|
54
66
|
|
|
55
67
|
config = process_loaded_project_config(config, errors, warnings)
|
|
56
68
|
federation, federation_config = validate_federation_in_project_config(
|
|
57
|
-
federation, config
|
|
69
|
+
federation, config, federation_config_overrides
|
|
58
70
|
)
|
|
59
71
|
exit_if_no_address(federation_config, "login")
|
|
72
|
+
|
|
73
|
+
# Check if `enable-user-auth` is set to `true`
|
|
74
|
+
if not federation_config.get("enable-user-auth", False):
|
|
75
|
+
typer.secho(
|
|
76
|
+
f"❌ User authentication is not enabled for the federation '{federation}'. "
|
|
77
|
+
"To enable it, set `enable-user-auth = true` in the federation "
|
|
78
|
+
"configuration.",
|
|
79
|
+
fg=typer.colors.RED,
|
|
80
|
+
bold=True,
|
|
81
|
+
)
|
|
82
|
+
raise typer.Exit(code=1)
|
|
83
|
+
|
|
60
84
|
channel = init_channel(app, federation_config, None)
|
|
61
85
|
stub = ExecStub(channel)
|
|
62
86
|
|
|
63
87
|
login_request = GetLoginDetailsRequest()
|
|
64
|
-
|
|
88
|
+
with unauthenticated_exc_handler():
|
|
89
|
+
login_response: GetLoginDetailsResponse = stub.GetLoginDetails(login_request)
|
|
65
90
|
|
|
66
91
|
# Get the auth plugin
|
|
67
|
-
auth_type = login_response.
|
|
68
|
-
auth_plugin = try_obtain_cli_auth_plugin(
|
|
92
|
+
auth_type = login_response.auth_type
|
|
93
|
+
auth_plugin = try_obtain_cli_auth_plugin(
|
|
94
|
+
app, federation, federation_config, auth_type
|
|
95
|
+
)
|
|
69
96
|
if auth_plugin is None:
|
|
70
97
|
typer.secho(
|
|
71
98
|
f'❌ Authentication type "{auth_type}" not found',
|
|
@@ -75,7 +102,15 @@ def login( # pylint: disable=R0914
|
|
|
75
102
|
raise typer.Exit(code=1)
|
|
76
103
|
|
|
77
104
|
# Login
|
|
78
|
-
|
|
105
|
+
details = UserAuthLoginDetails(
|
|
106
|
+
auth_type=login_response.auth_type,
|
|
107
|
+
device_code=login_response.device_code,
|
|
108
|
+
verification_uri_complete=login_response.verification_uri_complete,
|
|
109
|
+
expires_in=login_response.expires_in,
|
|
110
|
+
interval=login_response.interval,
|
|
111
|
+
)
|
|
112
|
+
with unauthenticated_exc_handler():
|
|
113
|
+
credentials = auth_plugin.login(details, stub)
|
|
79
114
|
|
|
80
115
|
# Store the tokens
|
|
81
|
-
auth_plugin.store_tokens(
|
|
116
|
+
auth_plugin.store_tokens(credentials)
|
flwr/cli/ls.py
CHANGED
|
@@ -32,6 +32,7 @@ from flwr.cli.config_utils import (
|
|
|
32
32
|
process_loaded_project_config,
|
|
33
33
|
validate_federation_in_project_config,
|
|
34
34
|
)
|
|
35
|
+
from flwr.cli.constant import FEDERATION_CONFIG_HELP_MESSAGE
|
|
35
36
|
from flwr.common.constant import FAB_CONFIG_FILE, CliOutputFormat, SubStatus
|
|
36
37
|
from flwr.common.date import format_timedelta, isoformat8601_utc
|
|
37
38
|
from flwr.common.logger import print_json_error, redirect_output, restore_output
|
|
@@ -48,7 +49,7 @@ from .utils import init_channel, try_obtain_cli_auth_plugin, unauthenticated_exc
|
|
|
48
49
|
_RunListType = tuple[int, str, str, str, str, str, str, str, str]
|
|
49
50
|
|
|
50
51
|
|
|
51
|
-
def ls( # pylint: disable=too-many-locals, too-many-branches
|
|
52
|
+
def ls( # pylint: disable=too-many-locals, too-many-branches, R0913, R0917
|
|
52
53
|
app: Annotated[
|
|
53
54
|
Path,
|
|
54
55
|
typer.Argument(help="Path of the Flower project"),
|
|
@@ -57,6 +58,13 @@ def ls( # pylint: disable=too-many-locals, too-many-branches
|
|
|
57
58
|
Optional[str],
|
|
58
59
|
typer.Argument(help="Name of the federation"),
|
|
59
60
|
] = None,
|
|
61
|
+
federation_config_overrides: Annotated[
|
|
62
|
+
Optional[list[str]],
|
|
63
|
+
typer.Option(
|
|
64
|
+
"--federation-config",
|
|
65
|
+
help=FEDERATION_CONFIG_HELP_MESSAGE,
|
|
66
|
+
),
|
|
67
|
+
] = None,
|
|
60
68
|
runs: Annotated[
|
|
61
69
|
bool,
|
|
62
70
|
typer.Option(
|
|
@@ -106,16 +114,16 @@ def ls( # pylint: disable=too-many-locals, too-many-branches
|
|
|
106
114
|
config, errors, warnings = load_and_validate(path=pyproject_path)
|
|
107
115
|
config = process_loaded_project_config(config, errors, warnings)
|
|
108
116
|
federation, federation_config = validate_federation_in_project_config(
|
|
109
|
-
federation, config
|
|
117
|
+
federation, config, federation_config_overrides
|
|
110
118
|
)
|
|
111
119
|
exit_if_no_address(federation_config, "ls")
|
|
112
|
-
|
|
120
|
+
channel = None
|
|
113
121
|
try:
|
|
114
122
|
if runs and run_id is not None:
|
|
115
123
|
raise ValueError(
|
|
116
124
|
"The options '--runs' and '--run-id' are mutually exclusive."
|
|
117
125
|
)
|
|
118
|
-
auth_plugin = try_obtain_cli_auth_plugin(app, federation)
|
|
126
|
+
auth_plugin = try_obtain_cli_auth_plugin(app, federation, federation_config)
|
|
119
127
|
channel = init_channel(app, federation_config, auth_plugin)
|
|
120
128
|
stub = ExecStub(channel)
|
|
121
129
|
|
|
@@ -140,7 +148,8 @@ def ls( # pylint: disable=too-many-locals, too-many-branches
|
|
|
140
148
|
)
|
|
141
149
|
raise typer.Exit(code=1) from err
|
|
142
150
|
finally:
|
|
143
|
-
channel
|
|
151
|
+
if channel:
|
|
152
|
+
channel.close()
|
|
144
153
|
except (typer.Exit, Exception) as err: # pylint: disable=broad-except
|
|
145
154
|
if suppress_output:
|
|
146
155
|
restore_output()
|