|
4 | 4 | from os import path |
5 | 5 | from typing import IO, Any, Dict, Optional, cast |
6 | 6 |
|
| 7 | +from splitgraph.config import CONFIG |
| 8 | +from splitgraph.config.config import get_singleton |
7 | 9 | from splitgraph.core.repository import Repository |
8 | 10 |
|
9 | 11 | RATHOLE_CLIENT_CONFIG_FILENAME = "rathole-client.toml" |
10 | 12 |
|
11 | 13 | RATHOLE_CLIENT_CONFIG_TEMPLATE = """ |
12 | 14 | [client] |
13 | | -remote_addr = "{tunnel_server_management_address}" |
| 15 | +remote_addr = "{tunnel_connect_address}" |
14 | 16 |
|
15 | 17 | [client.transport] |
16 | 18 | type = "tls" |
|
19 | 21 | {trusted_root_line} |
20 | 22 | hostname = "{tls_hostname}" |
21 | 23 |
|
22 | | -[client.services."{namespace}/{repository}"] |
| 24 | +[client.services."{section_id}"] |
23 | 25 | local_addr = "{local_address}" |
24 | | -# token is provisioner JWT token |
25 | | -token = "{provisioning_token}" |
| 26 | +token = "{secret_token}" |
26 | 27 |
|
27 | 28 | """ |
28 | 29 |
|
29 | 30 |
|
30 | 31 | def get_rathole_client_config( |
31 | | - tunnel_server_management_address: str, |
| 32 | + tunnel_connect_address: str, |
32 | 33 | tls_hostname: str, |
33 | 34 | local_address: str, |
34 | | - provisioning_token: str, |
35 | | - namespace: str, |
36 | | - repository: str, |
| 35 | + secret_token: str, |
| 36 | + section_id: str, |
37 | 37 | trusted_root: Optional[str], |
38 | 38 | ) -> str: |
39 | 39 | trusted_root_line = f'trusted_root = "{trusted_root}"' if trusted_root else "" |
40 | 40 | return RATHOLE_CLIENT_CONFIG_TEMPLATE.format( |
41 | | - tunnel_server_management_address=tunnel_server_management_address, |
| 41 | + tunnel_connect_address=tunnel_connect_address, |
42 | 42 | tls_hostname=tls_hostname, |
43 | 43 | local_address=local_address, |
44 | | - provisioning_token=provisioning_token, |
45 | | - namespace=namespace, |
46 | | - repository=repository, |
| 44 | + secret_token=secret_token, |
| 45 | + section_id=section_id, |
47 | 46 | trusted_root_line=trusted_root_line, |
48 | 47 | ) |
49 | 48 |
|
50 | 49 |
|
| 50 | +def get_rathole_client_binary_path(): |
| 51 | + config_dir = os.path.dirname(get_singleton(CONFIG, "SG_CONFIG_FILE")) |
| 52 | + return os.path.join(config_dir, "rathole") |
| 53 | + |
| 54 | + |
51 | 55 | def write_rathole_client_config( |
52 | | - provisioning_token: str, |
53 | | - tunnel_server_management_host: str, |
54 | | - tunnel_server_management_port: int, |
| 56 | + section_id: str, |
| 57 | + secret_token: str, |
| 58 | + tunnel_connect_host: str, |
| 59 | + tunnel_connect_port: int, |
| 60 | + local_address: str, |
55 | 61 | tls_hostname: Optional[str], |
56 | | - repository: Repository, |
57 | | - params: Dict[str, Any], |
58 | | - config_dir: str, |
59 | 62 | ) -> str: |
60 | 63 | # in production, this will be None, but for dev instances, we need to |
61 | 64 | # specify rootCA.pem |
| 65 | + config_dir = os.path.dirname(get_singleton(CONFIG, "SG_CONFIG_FILE")) |
62 | 66 | trusted_root = os.environ.get("REQUESTS_CA_BUNDLE") or os.environ.get("SSL_CERT_FILE") |
63 | 67 | rathole_client_config = get_rathole_client_config( |
64 | 68 | # TODO: replace these stub values with response of provisioning call |
65 | | - tunnel_server_management_address=f"{tunnel_server_management_host}:{tunnel_server_management_port}", |
66 | | - tls_hostname=tls_hostname or tunnel_server_management_host, |
67 | | - local_address=f"{params['host']}:{params['port']}", |
68 | | - provisioning_token=provisioning_token, |
69 | | - namespace=repository.namespace, |
70 | | - repository=repository.repository, |
| 69 | + tunnel_connect_address=f"{tunnel_connect_host}:{tunnel_connect_port}", |
| 70 | + tls_hostname=tls_hostname or tunnel_connect_host, |
| 71 | + local_address=local_address, |
| 72 | + secret_token=secret_token, |
| 73 | + section_id=section_id, |
71 | 74 | trusted_root=trusted_root, |
72 | 75 | ) |
73 | 76 | config_filename = path.join(config_dir, RATHOLE_CLIENT_CONFIG_FILENAME) |
|
0 commit comments