airbyte-internal-ops 0.1.9__py3-none-any.whl → 0.1.10__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {airbyte_internal_ops-0.1.9.dist-info → airbyte_internal_ops-0.1.10.dist-info}/METADATA +1 -1
- {airbyte_internal_ops-0.1.9.dist-info → airbyte_internal_ops-0.1.10.dist-info}/RECORD +7 -7
- airbyte_ops_mcp/cli/cloud.py +190 -0
- airbyte_ops_mcp/constants.py +9 -0
- airbyte_ops_mcp/prod_db_access/db_engine.py +143 -16
- {airbyte_internal_ops-0.1.9.dist-info → airbyte_internal_ops-0.1.10.dist-info}/WHEEL +0 -0
- {airbyte_internal_ops-0.1.9.dist-info → airbyte_internal_ops-0.1.10.dist-info}/entry_points.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
airbyte_ops_mcp/__init__.py,sha256=HhzURuYr29_UIdMrnWYaZB8ENr_kFkBdm4uqeiIW3Vw,760
|
|
2
2
|
airbyte_ops_mcp/_annotations.py,sha256=MO-SBDnbykxxHDESG7d8rviZZ4WlZgJKv0a8eBqcEzQ,1757
|
|
3
|
-
airbyte_ops_mcp/constants.py,sha256=
|
|
3
|
+
airbyte_ops_mcp/constants.py,sha256=col6-5BUWuIYhbtKmlvSRR8URBoSNExoz94cn4_kujI,2333
|
|
4
4
|
airbyte_ops_mcp/gcp_auth.py,sha256=5k-k145ZoYhHLjyDES8nrA8f8BBihRI0ykrdD1IcfOs,3599
|
|
5
5
|
airbyte_ops_mcp/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
6
|
airbyte_ops_mcp/_legacy/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -351,7 +351,7 @@ airbyte_ops_mcp/cli/__init__.py,sha256=XpL7FyVfgabfBF2JR7u7NwJ2krlYqjd_OwLcWf-Xc
|
|
|
351
351
|
airbyte_ops_mcp/cli/_base.py,sha256=I8tWnyQf0ks4r3J8N8h-5GZxyn37T-55KsbuHnxYlcg,415
|
|
352
352
|
airbyte_ops_mcp/cli/_shared.py,sha256=jg-xMyGzTCGPqKd8VTfE_3kGPIyO_3Kx5sQbG4rPc0Y,1311
|
|
353
353
|
airbyte_ops_mcp/cli/app.py,sha256=SEdBpqFUG2O8zGV5ifwptxrLGFph_dLr66-MX9d69gQ,789
|
|
354
|
-
airbyte_ops_mcp/cli/cloud.py,sha256=
|
|
354
|
+
airbyte_ops_mcp/cli/cloud.py,sha256=semAuPqruWfe7JiVmtbELZgcpeqtoIn4LGD0kEvIS30,38981
|
|
355
355
|
airbyte_ops_mcp/cli/gh.py,sha256=91b1AxFXvHQCFyXhrrym-756ZjnMCqvxFdmwCtma1zI,2046
|
|
356
356
|
airbyte_ops_mcp/cli/registry.py,sha256=-yiLJWSslV_qGi6ImXZYfXOJSE4oJBO7yICkyA_RiUo,5792
|
|
357
357
|
airbyte_ops_mcp/cli/repo.py,sha256=G1hoQpH0XYhUH3FFOsia9xabGB0LP9o3XcwBuqvFVo0,16331
|
|
@@ -400,14 +400,14 @@ airbyte_ops_mcp/mcp/registry.py,sha256=PW-VYUj42qx2pQ_apUkVaoUFq7VgB9zEU7-aGrkSC
|
|
|
400
400
|
airbyte_ops_mcp/mcp/server.py,sha256=7zi91xioVTx1q-bEleekZH2c2JnbzDQt_6zxdEwnLbg,2958
|
|
401
401
|
airbyte_ops_mcp/mcp/server_info.py,sha256=Yi4B1auW64QZGBDas5mro_vwTjvrP785TFNSBP7GhRg,2361
|
|
402
402
|
airbyte_ops_mcp/prod_db_access/__init__.py,sha256=5pxouMPY1beyWlB0UwPnbaLTKTHqU6X82rbbgKY2vYU,1069
|
|
403
|
-
airbyte_ops_mcp/prod_db_access/db_engine.py,sha256=
|
|
403
|
+
airbyte_ops_mcp/prod_db_access/db_engine.py,sha256=11xNZTk4I8SKYhsnmE7-LVrkJXN4dCRbBeD1_hj3f-s,9027
|
|
404
404
|
airbyte_ops_mcp/prod_db_access/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
405
405
|
airbyte_ops_mcp/prod_db_access/queries.py,sha256=q7PcI15EGh6jFS9MVB_gZt1a56YvrZV5hnwa5lgU2q0,10844
|
|
406
406
|
airbyte_ops_mcp/prod_db_access/sql.py,sha256=tWQAwMk8DzG8HpLIYglljlReI2oeYulQPsV31ocUJSw,16251
|
|
407
407
|
airbyte_ops_mcp/registry/__init__.py,sha256=iEaPlt9GrnlaLbc__98TguNeZG8wuQu7S-_2QkhHcbA,858
|
|
408
408
|
airbyte_ops_mcp/registry/models.py,sha256=B4L4TKr52wo0xs0CqvCBrpowqjShzVnZ5eTr2-EyhNs,2346
|
|
409
409
|
airbyte_ops_mcp/registry/publish.py,sha256=VoPxsM2_0zJ829orzCRN-kjgcJtuBNyXgW4I9J680ro,12717
|
|
410
|
-
airbyte_internal_ops-0.1.
|
|
411
|
-
airbyte_internal_ops-0.1.
|
|
412
|
-
airbyte_internal_ops-0.1.
|
|
413
|
-
airbyte_internal_ops-0.1.
|
|
410
|
+
airbyte_internal_ops-0.1.10.dist-info/METADATA,sha256=I3WAz4JM1tgyGMcFaV5ElRwvwYjlRLR9kXKzifetd1Q,5283
|
|
411
|
+
airbyte_internal_ops-0.1.10.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
412
|
+
airbyte_internal_ops-0.1.10.dist-info/entry_points.txt,sha256=eUgJ9xIy9PlR-CgRbqRMsh1NVp6jz08v9bul9vCYlU4,111
|
|
413
|
+
airbyte_internal_ops-0.1.10.dist-info/RECORD,,
|
airbyte_ops_mcp/cli/cloud.py
CHANGED
|
@@ -13,6 +13,12 @@ Commands:
|
|
|
13
13
|
from __future__ import annotations
|
|
14
14
|
|
|
15
15
|
import json
|
|
16
|
+
import os
|
|
17
|
+
import shutil
|
|
18
|
+
import signal
|
|
19
|
+
import socket
|
|
20
|
+
import subprocess
|
|
21
|
+
import time
|
|
16
22
|
from pathlib import Path
|
|
17
23
|
from typing import Annotated, Literal
|
|
18
24
|
|
|
@@ -30,6 +36,12 @@ from airbyte_ops_mcp.cli._shared import (
|
|
|
30
36
|
print_success,
|
|
31
37
|
)
|
|
32
38
|
from airbyte_ops_mcp.cloud_admin.connection_config import fetch_connection_config
|
|
39
|
+
from airbyte_ops_mcp.constants import (
|
|
40
|
+
CLOUD_SQL_INSTANCE,
|
|
41
|
+
CLOUD_SQL_PROXY_PID_FILE,
|
|
42
|
+
DEFAULT_CLOUD_SQL_PROXY_PORT,
|
|
43
|
+
ENV_GCP_PROD_DB_ACCESS_CREDENTIALS,
|
|
44
|
+
)
|
|
33
45
|
from airbyte_ops_mcp.live_tests.ci_output import (
|
|
34
46
|
generate_regression_report,
|
|
35
47
|
get_report_summary,
|
|
@@ -75,6 +87,184 @@ connector_app = App(
|
|
|
75
87
|
)
|
|
76
88
|
cloud_app.command(connector_app)
|
|
77
89
|
|
|
90
|
+
# Create the db sub-app under cloud
|
|
91
|
+
db_app = App(name="db", help="Database operations for Airbyte Cloud Prod DB Replica.")
|
|
92
|
+
cloud_app.command(db_app)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
@db_app.command(name="start-proxy")
|
|
96
|
+
def start_proxy(
|
|
97
|
+
port: Annotated[
|
|
98
|
+
int,
|
|
99
|
+
Parameter(help="Port for the Cloud SQL Proxy to listen on."),
|
|
100
|
+
] = DEFAULT_CLOUD_SQL_PROXY_PORT,
|
|
101
|
+
daemon: Annotated[
|
|
102
|
+
bool,
|
|
103
|
+
Parameter(
|
|
104
|
+
help="Run as daemon in background (default). Use --no-daemon for foreground."
|
|
105
|
+
),
|
|
106
|
+
] = True,
|
|
107
|
+
) -> None:
|
|
108
|
+
"""Start the Cloud SQL Proxy for database access.
|
|
109
|
+
|
|
110
|
+
This command starts the Cloud SQL Auth Proxy to enable connections to the
|
|
111
|
+
Airbyte Cloud Prod DB Replica. The proxy is required for database query tools.
|
|
112
|
+
|
|
113
|
+
By default, runs as a daemon (background process). Use --no-daemon to run in
|
|
114
|
+
foreground mode where you can see logs and stop with Ctrl+C.
|
|
115
|
+
|
|
116
|
+
Credentials are read from the GCP_PROD_DB_ACCESS_CREDENTIALS environment variable,
|
|
117
|
+
which should contain the service account JSON credentials.
|
|
118
|
+
|
|
119
|
+
After starting the proxy, set these environment variables to use database tools:
|
|
120
|
+
export USE_CLOUD_SQL_PROXY=1
|
|
121
|
+
export DB_PORT={port}
|
|
122
|
+
|
|
123
|
+
Example:
|
|
124
|
+
airbyte-ops cloud db start-proxy
|
|
125
|
+
airbyte-ops cloud db start-proxy --port 15432
|
|
126
|
+
airbyte-ops cloud db start-proxy --no-daemon
|
|
127
|
+
"""
|
|
128
|
+
# Check if proxy is already running on the requested port (idempotency)
|
|
129
|
+
try:
|
|
130
|
+
with socket.create_connection(("127.0.0.1", port), timeout=0.5):
|
|
131
|
+
# Something is already listening on this port
|
|
132
|
+
pid_file = Path(CLOUD_SQL_PROXY_PID_FILE)
|
|
133
|
+
pid_info = ""
|
|
134
|
+
if pid_file.exists():
|
|
135
|
+
pid_info = f" (PID: {pid_file.read_text().strip()})"
|
|
136
|
+
print_success(
|
|
137
|
+
f"Cloud SQL Proxy is already running on port {port}{pid_info}"
|
|
138
|
+
)
|
|
139
|
+
print_success("")
|
|
140
|
+
print_success("To use database tools, set these environment variables:")
|
|
141
|
+
print_success(" export USE_CLOUD_SQL_PROXY=1")
|
|
142
|
+
print_success(f" export DB_PORT={port}")
|
|
143
|
+
return
|
|
144
|
+
except (OSError, TimeoutError, ConnectionRefusedError):
|
|
145
|
+
pass # Port not in use, proceed with starting proxy
|
|
146
|
+
|
|
147
|
+
# Check if cloud-sql-proxy is installed
|
|
148
|
+
proxy_path = shutil.which("cloud-sql-proxy")
|
|
149
|
+
if not proxy_path:
|
|
150
|
+
exit_with_error(
|
|
151
|
+
"cloud-sql-proxy not found in PATH. "
|
|
152
|
+
"Install it from: https://cloud.google.com/sql/docs/mysql/sql-proxy"
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
# Get credentials from environment
|
|
156
|
+
creds_json = os.getenv(ENV_GCP_PROD_DB_ACCESS_CREDENTIALS)
|
|
157
|
+
if not creds_json:
|
|
158
|
+
exit_with_error(
|
|
159
|
+
f"{ENV_GCP_PROD_DB_ACCESS_CREDENTIALS} environment variable is not set. "
|
|
160
|
+
"This should contain the GCP service account JSON credentials."
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
# Build the command using --json-credentials to avoid writing to disk
|
|
164
|
+
cmd = [
|
|
165
|
+
proxy_path,
|
|
166
|
+
CLOUD_SQL_INSTANCE,
|
|
167
|
+
f"--port={port}",
|
|
168
|
+
f"--json-credentials={creds_json}",
|
|
169
|
+
]
|
|
170
|
+
|
|
171
|
+
print_success(f"Starting Cloud SQL Proxy on port {port}...")
|
|
172
|
+
print_success(f"Instance: {CLOUD_SQL_INSTANCE}")
|
|
173
|
+
print_success("")
|
|
174
|
+
print_success("To use database tools, set these environment variables:")
|
|
175
|
+
print_success(" export USE_CLOUD_SQL_PROXY=1")
|
|
176
|
+
print_success(f" export DB_PORT={port}")
|
|
177
|
+
print_success("")
|
|
178
|
+
|
|
179
|
+
if daemon:
|
|
180
|
+
# Run in background (daemon mode) with log file for diagnostics
|
|
181
|
+
log_file_path = Path("/tmp/airbyte-cloud-sql-proxy.log")
|
|
182
|
+
log_file = log_file_path.open("ab")
|
|
183
|
+
process = subprocess.Popen(
|
|
184
|
+
cmd,
|
|
185
|
+
stdout=subprocess.DEVNULL,
|
|
186
|
+
stderr=log_file,
|
|
187
|
+
start_new_session=True,
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
# Brief wait to verify the process started successfully
|
|
191
|
+
time.sleep(0.5)
|
|
192
|
+
if process.poll() is not None:
|
|
193
|
+
# Process exited immediately - read any error output
|
|
194
|
+
log_file.close()
|
|
195
|
+
error_output = ""
|
|
196
|
+
if log_file_path.exists():
|
|
197
|
+
error_output = log_file_path.read_text()[-1000:] # Last 1000 chars
|
|
198
|
+
exit_with_error(
|
|
199
|
+
f"Cloud SQL Proxy failed to start (exit code: {process.returncode}).\n"
|
|
200
|
+
f"Check logs at {log_file_path}\n"
|
|
201
|
+
f"Recent output: {error_output}"
|
|
202
|
+
)
|
|
203
|
+
|
|
204
|
+
# Write PID to file for stop-proxy command
|
|
205
|
+
pid_file = Path(CLOUD_SQL_PROXY_PID_FILE)
|
|
206
|
+
pid_file.write_text(str(process.pid))
|
|
207
|
+
print_success(f"Cloud SQL Proxy started as daemon (PID: {process.pid})")
|
|
208
|
+
print_success(f"Logs: {log_file_path}")
|
|
209
|
+
print_success("To stop: airbyte-ops cloud db stop-proxy")
|
|
210
|
+
else:
|
|
211
|
+
# Run in foreground - replace current process
|
|
212
|
+
# Signals (Ctrl+C) will be handled directly by the cloud-sql-proxy process
|
|
213
|
+
print_success("Running in foreground. Press Ctrl+C to stop the proxy.")
|
|
214
|
+
print_success("")
|
|
215
|
+
os.execv(proxy_path, cmd)
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
@db_app.command(name="stop-proxy")
|
|
219
|
+
def stop_proxy() -> None:
|
|
220
|
+
"""Stop the Cloud SQL Proxy daemon.
|
|
221
|
+
|
|
222
|
+
This command stops a Cloud SQL Proxy that was started with 'start-proxy'.
|
|
223
|
+
It reads the PID from the PID file and sends a SIGTERM signal to stop the process.
|
|
224
|
+
|
|
225
|
+
Example:
|
|
226
|
+
airbyte-ops cloud db stop-proxy
|
|
227
|
+
"""
|
|
228
|
+
pid_file = Path(CLOUD_SQL_PROXY_PID_FILE)
|
|
229
|
+
|
|
230
|
+
if not pid_file.exists():
|
|
231
|
+
exit_with_error(
|
|
232
|
+
f"PID file not found at {CLOUD_SQL_PROXY_PID_FILE}. "
|
|
233
|
+
"No Cloud SQL Proxy daemon appears to be running."
|
|
234
|
+
)
|
|
235
|
+
|
|
236
|
+
pid_str = pid_file.read_text().strip()
|
|
237
|
+
if not pid_str.isdigit():
|
|
238
|
+
pid_file.unlink()
|
|
239
|
+
exit_with_error(f"Invalid PID in {CLOUD_SQL_PROXY_PID_FILE}: {pid_str}")
|
|
240
|
+
|
|
241
|
+
pid = int(pid_str)
|
|
242
|
+
|
|
243
|
+
# Check if process is still running
|
|
244
|
+
try:
|
|
245
|
+
os.kill(pid, 0) # Signal 0 just checks if process exists
|
|
246
|
+
except ProcessLookupError:
|
|
247
|
+
pid_file.unlink()
|
|
248
|
+
print_success(
|
|
249
|
+
f"Cloud SQL Proxy (PID: {pid}) is not running. Cleaned up PID file."
|
|
250
|
+
)
|
|
251
|
+
return
|
|
252
|
+
except PermissionError:
|
|
253
|
+
exit_with_error(f"Permission denied to check process {pid}.")
|
|
254
|
+
|
|
255
|
+
# Send SIGTERM to stop the process
|
|
256
|
+
try:
|
|
257
|
+
os.kill(pid, signal.SIGTERM)
|
|
258
|
+
print_success(f"Sent SIGTERM to Cloud SQL Proxy (PID: {pid}).")
|
|
259
|
+
except ProcessLookupError:
|
|
260
|
+
print_success(f"Cloud SQL Proxy (PID: {pid}) already stopped.")
|
|
261
|
+
except PermissionError:
|
|
262
|
+
exit_with_error(f"Permission denied to stop process {pid}.")
|
|
263
|
+
|
|
264
|
+
# Clean up PID file
|
|
265
|
+
pid_file.unlink(missing_ok=True)
|
|
266
|
+
print_success("Cloud SQL Proxy stopped.")
|
|
267
|
+
|
|
78
268
|
|
|
79
269
|
@connector_app.command(name="get-version-info")
|
|
80
270
|
def get_version_info(
|
airbyte_ops_mcp/constants.py
CHANGED
|
@@ -27,6 +27,15 @@ EXPECTED_ADMIN_EMAIL_DOMAIN = "@airbyte.io"
|
|
|
27
27
|
GCP_PROJECT_NAME = "prod-ab-cloud-proj"
|
|
28
28
|
"""The GCP project name for Airbyte Cloud production."""
|
|
29
29
|
|
|
30
|
+
CLOUD_SQL_INSTANCE = "prod-ab-cloud-proj:us-west3:prod-pgsql-replica"
|
|
31
|
+
"""The Cloud SQL instance connection name for the Prod DB Replica."""
|
|
32
|
+
|
|
33
|
+
DEFAULT_CLOUD_SQL_PROXY_PORT = 15432
|
|
34
|
+
"""Default port for Cloud SQL Proxy connections."""
|
|
35
|
+
|
|
36
|
+
CLOUD_SQL_PROXY_PID_FILE = "/tmp/airbyte-cloud-sql-proxy.pid"
|
|
37
|
+
"""PID file for tracking the Cloud SQL Proxy process."""
|
|
38
|
+
|
|
30
39
|
CLOUD_REGISTRY_URL = (
|
|
31
40
|
"https://connectors.airbyte.com/files/registries/v0/cloud_registry.json"
|
|
32
41
|
)
|
|
@@ -11,7 +11,9 @@ from __future__ import annotations
|
|
|
11
11
|
|
|
12
12
|
import json
|
|
13
13
|
import os
|
|
14
|
-
import
|
|
14
|
+
import shutil
|
|
15
|
+
import socket
|
|
16
|
+
import subprocess
|
|
15
17
|
from typing import Any, Callable
|
|
16
18
|
|
|
17
19
|
import sqlalchemy
|
|
@@ -21,9 +23,127 @@ from google.cloud.sql.connector.enums import IPTypes
|
|
|
21
23
|
|
|
22
24
|
from airbyte_ops_mcp.constants import (
|
|
23
25
|
CONNECTION_RETRIEVER_PG_CONNECTION_DETAILS_SECRET_ID,
|
|
26
|
+
DEFAULT_CLOUD_SQL_PROXY_PORT,
|
|
24
27
|
)
|
|
25
28
|
|
|
26
29
|
PG_DRIVER = "pg8000"
|
|
30
|
+
PROXY_CHECK_TIMEOUT = 0.5 # seconds
|
|
31
|
+
DIRECT_CONNECTION_TIMEOUT = 5 # seconds - timeout for direct VPC/Tailscale connections
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class CloudSqlProxyNotRunningError(Exception):
|
|
35
|
+
"""Raised when proxy mode is enabled but the Cloud SQL Proxy is not running."""
|
|
36
|
+
|
|
37
|
+
pass
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class VpnNotConnectedError(Exception):
|
|
41
|
+
"""Raised when direct connection mode requires VPN but it's not connected."""
|
|
42
|
+
|
|
43
|
+
pass
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _is_tailscale_connected() -> bool:
|
|
47
|
+
"""Check if Tailscale VPN is likely connected.
|
|
48
|
+
|
|
49
|
+
This is a best-effort check that works on Linux and macOS.
|
|
50
|
+
Returns True if Tailscale appears to be connected, False otherwise.
|
|
51
|
+
|
|
52
|
+
Detection methods:
|
|
53
|
+
1. Check for tailscale0 network interface (Linux)
|
|
54
|
+
2. Run 'tailscale status --json' and check backend state (cross-platform)
|
|
55
|
+
"""
|
|
56
|
+
# Method 1: Check for tailscale0 interface (Linux)
|
|
57
|
+
try:
|
|
58
|
+
interfaces = [name for _, name in socket.if_nameindex()]
|
|
59
|
+
if "tailscale0" in interfaces:
|
|
60
|
+
return True
|
|
61
|
+
except (OSError, AttributeError):
|
|
62
|
+
pass # if_nameindex not available on this platform
|
|
63
|
+
|
|
64
|
+
# Method 2: Check tailscale CLI status
|
|
65
|
+
tailscale_path = shutil.which("tailscale")
|
|
66
|
+
if tailscale_path:
|
|
67
|
+
try:
|
|
68
|
+
result = subprocess.run(
|
|
69
|
+
[tailscale_path, "status", "--json"],
|
|
70
|
+
capture_output=True,
|
|
71
|
+
text=True,
|
|
72
|
+
timeout=2,
|
|
73
|
+
)
|
|
74
|
+
if result.returncode == 0:
|
|
75
|
+
import json as json_module
|
|
76
|
+
|
|
77
|
+
status = json_module.loads(result.stdout)
|
|
78
|
+
# BackendState "Running" indicates connected
|
|
79
|
+
return status.get("BackendState") == "Running"
|
|
80
|
+
except (subprocess.TimeoutExpired, subprocess.SubprocessError, ValueError):
|
|
81
|
+
pass
|
|
82
|
+
|
|
83
|
+
return False
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def _check_vpn_or_proxy_available() -> None:
|
|
87
|
+
"""Check if either VPN or proxy is available for database access.
|
|
88
|
+
|
|
89
|
+
This function checks if the environment is properly configured for
|
|
90
|
+
database access. It fails fast with a helpful error message if neither
|
|
91
|
+
Tailscale VPN nor the Cloud SQL Proxy appears to be available.
|
|
92
|
+
|
|
93
|
+
Raises:
|
|
94
|
+
VpnNotConnectedError: If no VPN or proxy is detected
|
|
95
|
+
"""
|
|
96
|
+
# If proxy mode is explicitly enabled, don't check VPN
|
|
97
|
+
if os.getenv("CI") or os.getenv("USE_CLOUD_SQL_PROXY"):
|
|
98
|
+
return
|
|
99
|
+
|
|
100
|
+
# Check if Tailscale is connected
|
|
101
|
+
if _is_tailscale_connected():
|
|
102
|
+
return
|
|
103
|
+
|
|
104
|
+
# Neither proxy mode nor Tailscale detected
|
|
105
|
+
raise VpnNotConnectedError(
|
|
106
|
+
"No VPN or proxy detected for database access.\n\n"
|
|
107
|
+
"To connect to the Airbyte Cloud Prod DB Replica, you need either:\n\n"
|
|
108
|
+
"1. Tailscale VPN connected (for direct VPC access)\n"
|
|
109
|
+
" - Install Tailscale: https://tailscale.com/download\n"
|
|
110
|
+
" - Connect to the Airbyte network\n\n"
|
|
111
|
+
"2. Cloud SQL Proxy running locally\n"
|
|
112
|
+
" - Start the proxy:\n"
|
|
113
|
+
" airbyte-ops cloud db start-proxy\n"
|
|
114
|
+
" uvx --from=airbyte-internal-ops airbyte-ops cloud db start-proxy\n"
|
|
115
|
+
" - Set env vars: export USE_CLOUD_SQL_PROXY=1 DB_PORT=15432\n"
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def _check_proxy_is_running(host: str, port: int) -> None:
|
|
120
|
+
"""Check if the Cloud SQL Proxy is running and accepting connections.
|
|
121
|
+
|
|
122
|
+
This performs a quick socket connection check to fail fast if the proxy
|
|
123
|
+
is not running, rather than waiting for a long connection timeout.
|
|
124
|
+
|
|
125
|
+
Args:
|
|
126
|
+
host: The host to connect to (typically 127.0.0.1)
|
|
127
|
+
port: The port to connect to
|
|
128
|
+
|
|
129
|
+
Raises:
|
|
130
|
+
CloudSqlProxyNotRunningError: If the proxy is not accepting connections
|
|
131
|
+
"""
|
|
132
|
+
try:
|
|
133
|
+
with socket.create_connection((host, port), timeout=PROXY_CHECK_TIMEOUT):
|
|
134
|
+
pass # Connection successful, proxy is running
|
|
135
|
+
except (OSError, TimeoutError, ConnectionRefusedError) as e:
|
|
136
|
+
raise CloudSqlProxyNotRunningError(
|
|
137
|
+
f"Cloud SQL Proxy is not running on {host}:{port}. "
|
|
138
|
+
f"Proxy mode is enabled (CI or USE_CLOUD_SQL_PROXY env var is set), "
|
|
139
|
+
f"but nothing is listening on the expected port.\n\n"
|
|
140
|
+
f"To start the proxy, run:\n"
|
|
141
|
+
f" airbyte-ops cloud db start-proxy --port {port}\n"
|
|
142
|
+
f" uvx --from=airbyte-internal-ops airbyte-ops cloud db start-proxy --port {port}\n\n"
|
|
143
|
+
f"Or unset USE_CLOUD_SQL_PROXY to use direct VPC connection.\n\n"
|
|
144
|
+
f"Original error: {e}"
|
|
145
|
+
) from e
|
|
146
|
+
|
|
27
147
|
|
|
28
148
|
# Lazy-initialized to avoid import-time GCP auth
|
|
29
149
|
_connector: Connector | None = None
|
|
@@ -81,16 +201,20 @@ def get_pool(
|
|
|
81
201
|
"""Get a SQLAlchemy connection pool for the Airbyte Cloud database.
|
|
82
202
|
|
|
83
203
|
This function supports two connection modes:
|
|
84
|
-
1. Direct connection via Cloud SQL Python Connector (default, requires VPC
|
|
204
|
+
1. Direct connection via Cloud SQL Python Connector (default, requires VPC/Tailscale)
|
|
85
205
|
2. Connection via Cloud SQL Auth Proxy (when CI or USE_CLOUD_SQL_PROXY env var is set)
|
|
86
206
|
|
|
87
207
|
For proxy mode, start the proxy with:
|
|
88
|
-
|
|
208
|
+
airbyte-ops cloud db start-proxy
|
|
89
209
|
|
|
90
210
|
Environment variables:
|
|
91
211
|
CI: If set, uses proxy connection mode
|
|
92
212
|
USE_CLOUD_SQL_PROXY: If set, uses proxy connection mode
|
|
93
|
-
DB_PORT: Port for proxy connection (default:
|
|
213
|
+
DB_PORT: Port for proxy connection (default: 15432)
|
|
214
|
+
|
|
215
|
+
Raises:
|
|
216
|
+
VpnNotConnectedError: If direct mode is used but no VPN/proxy is detected
|
|
217
|
+
CloudSqlProxyNotRunningError: If proxy mode is enabled but the proxy is not running
|
|
94
218
|
|
|
95
219
|
Args:
|
|
96
220
|
gsm_client: GCP Secret Manager client for retrieving credentials
|
|
@@ -98,6 +222,9 @@ def get_pool(
|
|
|
98
222
|
Returns:
|
|
99
223
|
SQLAlchemy Engine connected to the Prod DB Replica
|
|
100
224
|
"""
|
|
225
|
+
# Fail fast if no VPN or proxy is available
|
|
226
|
+
_check_vpn_or_proxy_available()
|
|
227
|
+
|
|
101
228
|
pg_connection_details = json.loads(
|
|
102
229
|
_get_secret_value(
|
|
103
230
|
gsm_client, CONNECTION_RETRIEVER_PG_CONNECTION_DETAILS_SECRET_ID
|
|
@@ -106,21 +233,21 @@ def get_pool(
|
|
|
106
233
|
|
|
107
234
|
if os.getenv("CI") or os.getenv("USE_CLOUD_SQL_PROXY"):
|
|
108
235
|
# Connect via Cloud SQL Auth Proxy, running on localhost
|
|
109
|
-
# Port can be configured via DB_PORT env var (default:
|
|
236
|
+
# Port can be configured via DB_PORT env var (default: DEFAULT_CLOUD_SQL_PROXY_PORT)
|
|
110
237
|
host = "127.0.0.1"
|
|
111
|
-
port = os.getenv("DB_PORT",
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
f"Error: {traceback.format_exception(e)}"
|
|
120
|
-
) from e
|
|
238
|
+
port = int(os.getenv("DB_PORT", str(DEFAULT_CLOUD_SQL_PROXY_PORT)))
|
|
239
|
+
|
|
240
|
+
# Fail fast if proxy is not running
|
|
241
|
+
_check_proxy_is_running(host, port)
|
|
242
|
+
|
|
243
|
+
return sqlalchemy.create_engine(
|
|
244
|
+
f"postgresql+{PG_DRIVER}://{pg_connection_details['pg_user']}:{pg_connection_details['pg_password']}@{host}:{port}/{pg_connection_details['database_name']}",
|
|
245
|
+
)
|
|
121
246
|
|
|
122
|
-
# Default: Connect via Cloud SQL Python Connector (requires VPC access)
|
|
247
|
+
# Default: Connect via Cloud SQL Python Connector (requires VPC/Tailscale access)
|
|
248
|
+
# Use a timeout to fail faster if the connection can't be established
|
|
123
249
|
return sqlalchemy.create_engine(
|
|
124
250
|
f"postgresql+{PG_DRIVER}://",
|
|
125
251
|
creator=get_database_creator(pg_connection_details),
|
|
252
|
+
connect_args={"timeout": DIRECT_CONNECTION_TIMEOUT},
|
|
126
253
|
)
|
|
File without changes
|
{airbyte_internal_ops-0.1.9.dist-info → airbyte_internal_ops-0.1.10.dist-info}/entry_points.txt
RENAMED
|
File without changes
|