Skip to content

Commit

Permalink
add sys.exit and exception when configs are wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
panh99 committed Nov 28, 2023
1 parent 8b575e9 commit 7d2df1f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/py/flwr/client/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ def run_client() -> None:

# Obtain certificates
if args.insecure:
if args.root_certificates is not None:
sys.exit(
"Conflicting options: The '--insecure' flag disables HTTPS, "
"but '--root-certificates' was also specified. Please remove "
"the '--root-certificates' option when running in insecure mode, "
"or omit '--insecure' to use HTTPS."
)
log(WARN, "Option `--insecure` was set. Starting insecure HTTP client.")
root_certificates = None
else:
Expand Down Expand Up @@ -94,9 +101,8 @@ def _parse_args_client() -> argparse.ArgumentParser:
parser.add_argument(
"--insecure",
action="store_true",
help="Run the client without HTTPS, regardless of whether certificate "
"paths are provided. By default, the client runs with HTTPS enabled. "
"Use this flag only if you understand the risks.",
help="Run the client without HTTPS. By default, the client runs with "
"HTTPS enabled. Use this flag only if you understand the risks.",
)
parser.add_argument(
"--root-certificates",
Expand Down
8 changes: 8 additions & 0 deletions src/py/flwr/common/grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ def create_channel(
max_message_length: int = GRPC_MAX_MESSAGE_LENGTH,
) -> grpc.Channel:
"""Create a gRPC channel, either secure or insecure."""
# Check for conflicting parameters
if insecure and root_certificates is not None:
raise ValueError(
"Invalid configuration: 'root_certificates' should not be provided "
"when 'insecure' is set to True. For an insecure connection, omit "
"'root_certificates', or set 'insecure' to False for a secure connection."
)

# Possible options:
# https://github.com/grpc/grpc/blob/v1.43.x/include/grpc/impl/codegen/grpc_types.h
channel_options = [
Expand Down

0 comments on commit 7d2df1f

Please sign in to comment.