Skip to content

Commit

Permalink
Do not display info messages when json format is used.
Browse files Browse the repository at this point in the history
  • Loading branch information
gbregman committed Sep 2, 2024
1 parent 9f7ecbd commit 4e11d17
Showing 1 changed file with 9 additions and 4 deletions.
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

0 comments on commit 4e11d17

Please sign in to comment.