[Notes] [Git][BuildGrid/buildgrid][finn/78-capabilities-service] buildgrid/_app/commands/cmd_capabilities.py: New command.



Title: GitLab

finn pushed to branch finn/78-capabilities-service at BuildGrid / buildgrid

Commits:

1 changed file:

Changes:

  • buildgrid/_app/commands/cmd_capabilities.py
    1
    +# Copyright (C) 2018 Bloomberg LP
    
    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
    +
    
    16
    +import sys
    
    17
    +from urllib.parse import urlparse
    
    18
    +
    
    19
    +import click
    
    20
    +import grpc
    
    21
    +
    
    22
    +from buildgrid.client.capabilities import CapabilitiesInterface
    
    23
    +
    
    24
    +from ..cli import pass_context
    
    25
    +
    
    26
    +
    
    27
    +@click.command(name='capabilities', short_help="Capabilities service.")
    
    28
    +@click.option('--remote', type=click.STRING, default='http://localhost:50051', show_default=True,
    
    29
    +              help="Remote execution server's URL (port defaults to 50051 if no specified).")
    
    30
    +@click.option('--client-key', type=click.Path(exists=True, dir_okay=False), default=None,
    
    31
    +              help="Private client key for TLS (PEM-encoded)")
    
    32
    +@click.option('--client-cert', type=click.Path(exists=True, dir_okay=False), default=None,
    
    33
    +              help="Public client certificate for TLS (PEM-encoded)")
    
    34
    +@click.option('--server-cert', type=click.Path(exists=True, dir_okay=False), default=None,
    
    35
    +              help="Public server certificate for TLS (PEM-encoded)")
    
    36
    +@click.option('--instance-name', type=click.STRING, default='main', show_default=True,
    
    37
    +              help="Targeted farm instance name.")
    
    38
    +def cli(remote, instance_name, client_key, client_cert, server_cert):
    
    39
    +    click.echo("Getting capabilities...")
    
    40
    +    url = urlparse(remote)
    
    41
    +
    
    42
    +    remote = '{}:{}'.format(url.hostname, url.port or 50051)
    
    43
    +    instance_name = instance_name
    
    44
    +
    
    45
    +    if url.scheme == 'http':
    
    46
    +        channel = grpc.insecure_channel(remote)
    
    47
    +    else:
    
    48
    +        credentials = load_client_credentials(client_key, client_cert, server_cert)
    
    49
    +        if not credentials:
    
    50
    +            click.echo("ERROR: no TLS keys were specified and no defaults could be found.", err=True)
    
    51
    +            sys.exit(-1)
    
    52
    +
    
    53
    +        channel = grpc.secure_channel(remote, credentials)
    
    54
    +
    
    55
    +    interface = CapabilitiesInterface(channel)
    
    56
    +    response = interface.get_capabilities(instance_name)
    
    57
    +    click.echo(response)



  • [Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]