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