Skip to content
Snippets Groups Projects
Commit 5117f6b9 authored by finnball's avatar finnball
Browse files

Added remote parser.

Constructs a channel using the `Context` class and passes it into
the `RemoteStorage` class
parent ebb04267
No related branches found
No related tags found
Loading
......@@ -14,7 +14,11 @@
import os
import sys
from urllib.parse import urlparse
import click
import grpc
import yaml
from buildgrid.server.controller import ExecutionController
......@@ -22,9 +26,12 @@ from buildgrid.server.actioncache.storage import ActionCache
from buildgrid.server.cas.instance import ByteStreamInstance, ContentAddressableStorageInstance
from buildgrid.server.cas.storage.disk import DiskStorage
from buildgrid.server.cas.storage.lru_memory_cache import LRUMemoryCache
from buildgrid.server.cas.storage.remote import RemoteStorage
from buildgrid.server.cas.storage.s3 import S3Storage
from buildgrid.server.cas.storage.with_cache import WithCacheStorage
from ..cli import Context
class YamlFactory(yaml.YAMLObject):
@classmethod
......@@ -58,6 +65,45 @@ class S3(YamlFactory):
return S3Storage(bucket, endpoint_url=endpoint)
class Remote(YamlFactory):
yaml_tag = u'!remote-storage'
def __new__(cls, url, credentials=None):
# TODO: Context could be passed into the parser.
context = Context()
url = urlparse(url)
remote = '{}:{}'.format(url.hostname, url.port or 50051)
channel = None
if url.scheme == 'http':
channel = grpc.insecure_channel(remote)
else:
if not credentials:
click.echo("ERROR: no TLS keys were specified and no defaults could be found.\n" +
"Set remote url scheme to `http` in order to deactivate" +
"TLS encryption.\n", err=True)
sys.exit(-1)
client_key = credentials['tls-client-key']
client_cert = credentials['tls-client-cert']
server_cert = credentials['tls-server-cert']
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.\n" +
"Set remote url scheme to `http` in order to deactivate" +
"TLS encryption.\n", err=True)
sys.exit(-1)
channel = grpc.secure_channel(remote, credentials)
return RemoteStorage(channel)
class WithCache(YamlFactory):
yaml_tag = u'!with-cache-storage'
......@@ -118,6 +164,7 @@ def get_parser():
yaml.SafeLoader.add_constructor(Disk.yaml_tag, Disk.from_yaml)
yaml.SafeLoader.add_constructor(LRU.yaml_tag, LRU.from_yaml)
yaml.SafeLoader.add_constructor(S3.yaml_tag, S3.from_yaml)
yaml.SafeLoader.add_constructor(Remote.yaml_tag, Remote.from_yaml)
yaml.SafeLoader.add_constructor(WithCache.yaml_tag, WithCache.from_yaml)
yaml.SafeLoader.add_constructor(CAS.yaml_tag, CAS.from_yaml)
yaml.SafeLoader.add_constructor(ByteStream.yaml_tag, ByteStream.from_yaml)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment