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

Do not display info messages when json format is used #847

Merged
merged 1 commit into from
Sep 2, 2024
Merged
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
13 changes: 9 additions & 4 deletions control/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,15 +205,20 @@ def stub(self):
raise AttributeError("stub is None. Set with connect method.")
return self._stub

def connect(self, host, port, client_key, client_cert, server_cert):
def connect(self, args, host, port, client_key, client_cert, server_cert):
"""Connects to server and sets stub."""
out_func, err_func = self.get_output_functions(args)
if args.format == "json" or args.format == "yaml" or args.format == "python":
out_func = None

# We need to enclose IPv6 addresses in brackets before concatenating a colon and port number to it
host = GatewayUtils.escape_address_if_ipv6(host)
server = f"{host}:{port}"

if client_key and client_cert:
# Create credentials for mutual TLS and a secure channel
self.logger.info("Enable server auth since both --client-key and --client-cert are provided")
if out_func:
out_func("Enable server auth since both --client-key and --client-cert are provided")
with client_cert as f:
client_cert = f.read()
with client_key as f:
Expand All @@ -222,7 +227,7 @@ def connect(self, host, port, client_key, client_cert, server_cert):
with server_cert as f:
server_cert = f.read()
else:
self.logger.warn("No server certificate file was provided")
err_func("No server certificate file was provided")

credentials = grpc.ssl_channel_credentials(
root_certificates=server_cert,
Expand Down Expand Up @@ -1872,7 +1877,7 @@ def main_common(client, args):
client_key = args.client_key
client_cert = args.client_cert
server_cert = args.server_cert
client.connect(server_address, server_port, client_key, client_cert, server_cert)
client.connect(args, server_address, server_port, client_key, client_cert, server_cert)
call_function = getattr(client, args.func.__name__)
rc = call_function(args)
return rc
Expand Down
Loading