Skip to content
Snippets Groups Projects
Commit 820c3a29 authored by Martin Blanchard's avatar Martin Blanchard
Browse files

cmd_operation.py: Port‧to‧new‧client‧channel‧helpers

parent 550e581c
No related branches found
No related tags found
No related merge requests found
......@@ -30,7 +30,9 @@ import click
from google.protobuf import json_format
import grpc
from buildgrid.client.authentication import setup_channel
from buildgrid._enums import OperationStage
from buildgrid._exceptions import InvalidArgumentError
from buildgrid._protos.build.bazel.remote.execution.v2 import remote_execution_pb2, remote_execution_pb2_grpc
from buildgrid._protos.google.longrunning import operations_pb2, operations_pb2_grpc
from buildgrid._protos.google.rpc import code_pb2
......@@ -41,32 +43,27 @@ from ..cli import pass_context
@click.group(name='operation', short_help="Long running operations commands.")
@click.option('--remote', type=click.STRING, default='http://localhost:50051', show_default=True,
help="Remote execution server's URL (port defaults to 50051 if no specified).")
@click.option('--auth-token', type=click.Path(exists=True, dir_okay=False), default=None,
help="Authorization token for the remote.")
@click.option('--client-key', type=click.Path(exists=True, dir_okay=False), default=None,
help="Private client key for TLS (PEM-encoded)")
help="Private client key for TLS (PEM-encoded).")
@click.option('--client-cert', type=click.Path(exists=True, dir_okay=False), default=None,
help="Public client certificate for TLS (PEM-encoded)")
help="Public client certificate for TLS (PEM-encoded).")
@click.option('--server-cert', type=click.Path(exists=True, dir_okay=False), default=None,
help="Public server certificate for TLS (PEM-encoded)")
help="Public server certificate for TLS (PEM-encoded).")
@click.option('--instance-name', type=click.STRING, default='main', show_default=True,
help="Targeted farm instance name.")
@pass_context
def cli(context, remote, instance_name, client_key, client_cert, server_cert):
url = urlparse(remote)
"""Entry point for the bgd-operation CLI command group."""
try:
context.channel = setup_channel(remote, authorization_token=auth_token,
client_key=client_key, client_cert=client_cert)
context.remote = '{}:{}'.format(url.hostname, url.port or 50051)
context.instance_name = instance_name
if url.scheme == 'http':
context.channel = grpc.insecure_channel(context.remote)
else:
credentials = context.load_client_credentials(client_key, client_cert, server_cert)
if not credentials:
click.echo("ERROR: no TLS keys were specified and no defaults could be found.", err=True)
sys.exit(-1)
except InvalidArgumentError as e:
click.echo("Error: {}.".format(e), err=True)
context.channel = grpc.secure_channel(context.remote, credentials)
click.echo("Starting for remote=[{}]".format(context.remote))
context.instance_name = instance_name
def _print_operation_status(operation, print_details=False):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment