Skip to content

Commit

Permalink
Update client-side rathole config to use same section name as server
Browse files Browse the repository at this point in the history
  • Loading branch information
neumark committed Oct 19, 2022
1 parent 9de7092 commit cae87c9
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 28 deletions.
5 changes: 4 additions & 1 deletion splitgraph/cloud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,9 @@ def load_all_repositories(self, limit_to: List[str] = None) -> List[Repository]:

return make_repositories(parsed_metadata, parsed_external)

def provision_repository_tunnel(self, namespace: str, repository: str) -> Tuple[str, str, int]:
def provision_repository_tunnel(
self, namespace: str, repository: str
) -> Tuple[str, str, int, str]:
response = self._gql(
{
"query": PROVISION_REPOSITORY_TUNNEL,
Expand All @@ -1121,6 +1123,7 @@ def provision_repository_tunnel(self, namespace: str, repository: str) -> Tuple[
response.json()["data"]["provisionRepositoryTunnel"]["secretToken"],
response.json()["data"]["provisionRepositoryTunnel"]["tunnelConnectHost"],
response.json()["data"]["provisionRepositoryTunnel"]["tunnelConnectPort"],
response.json()["data"]["provisionRepositoryTunnel"]["privateAddressHost"],
)

def provision_ephemeral_tunnel(self) -> Tuple[str, str, int, str, int]:
Expand Down
3 changes: 2 additions & 1 deletion splitgraph/cloud/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@
provisionRepositoryTunnel(namespace:$namespace, repository:$repository) {
secretToken,
tunnelConnectHost,
tunnelConnectPort
tunnelConnectPort,
privateAddressHost
}
}
"""
Expand Down
13 changes: 7 additions & 6 deletions splitgraph/commandline/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -1227,14 +1227,15 @@ def start_repository_tunnel(remote: str, local_address: str, namespace_and_repos
client = GQLAPIClient(remote)

(namespace, repository) = parse_repository(namespace_and_repository)
(secret_token, tunnel_connect_host, tunnel_connect_port) = client.provision_repository_tunnel(
namespace, repository
)

section_id = f"{namespace}/{repository}"
(
secret_token,
tunnel_connect_host,
tunnel_connect_port,
private_address_host,
) = client.provision_repository_tunnel(namespace, repository)

write_rathole_client_config(
section_id,
private_address_host,
secret_token,
tunnel_connect_host,
tunnel_connect_port,
Expand Down
3 changes: 0 additions & 3 deletions test/splitgraph/commandline/http_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,6 @@ def cb(request, uri, response_headers):
},
"schedule": None,
"initial_private": initial_private,
"tunnel": False,
},
{
"namespace": "someuser",
Expand All @@ -435,7 +434,6 @@ def cb(request, uri, response_headers):
"credential_id": "123e4567-e89b-12d3-a456-426655440000",
"schedule": None,
"initial_private": initial_private,
"tunnel": False,
},
{
"namespace": "someuser",
Expand All @@ -447,7 +445,6 @@ def cb(request, uri, response_headers):
"credential_id": "00000000-0000-0000-0000-000000000000",
"schedule": None,
"initial_private": initial_private,
"tunnel": False,
},
]

Expand Down
37 changes: 20 additions & 17 deletions test/splitgraph/commandline/test_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
from httpretty.core import HTTPrettyRequest

from splitgraph.__version__ import __version__
from splitgraph.cloud.project.models import External
from splitgraph.cloud.tunnel_client import get_config_filename
from splitgraph.commandline import cli
from splitgraph.commandline.cloud import (
Expand Down Expand Up @@ -631,26 +630,30 @@ def test_commandline_stub(snapshot):

def test_rathole_client_config():
runner = CliRunner(mix_stderr=False)
external = External(
tunnel=True, plugin="asdf", params={"host": "127.0.0.1", "port": 5432}, tables={}
)

def mock_provision_tunnel(a, b):
print("asdf", a, b)
return ("foo", "bar", 1)
secret_token = "secret_token"
local_address = "127.0.0.1:5432"
tunnel_host = "data.splitgraph.test"
tunnel_port = 2333
private_ip6_address = "fd71:dac6:df45:7f99:d875:ece2:e581:36ea"

def mock_provision_tunnel(_a, _b):
return (
secret_token,
tunnel_host,
tunnel_port,
private_ip6_address,
)

with patch(
"splitgraph.commandline.cloud._get_external_from_yaml", return_value=(external,)
), patch(
"splitgraph.cloud.GQLAPIClient.provision_repository_tunnel",
new_callable=PropertyMock,
return_value=mock_provision_tunnel,
), patch(
"splitgraph.commandline.cloud.launch_rathole_client", return_value=None
):
), patch("splitgraph.commandline.cloud.launch_rathole_client", return_value=None):
result = runner.invoke(
tunnel_c,
[
local_address,
"test/repo",
],
catch_exceptions=False,
Expand All @@ -660,12 +663,12 @@ def mock_provision_tunnel(a, b):
non_empty_lines = [line.strip() for line in f if line.strip() != ""]
assert non_empty_lines == [
"[client]",
'remote_addr = "bar:1"',
'remote_addr = "%s:%s"' % (tunnel_host, tunnel_port),
"[client.transport]",
'type = "tls"',
"[client.transport.tls]",
'hostname = "bar"',
'[client.services."test/repo"]',
'local_addr = "127.0.0.1:5432"',
'token = "foo"',
'hostname = "%s"' % tunnel_host,
'[client.services."%s"]' % private_ip6_address,
'local_addr = "%s"' % local_address,
'token = "%s"' % secret_token,
]

0 comments on commit cae87c9

Please sign in to comment.