git.iko.soy/typeable/nixpkgs
on master help sign in
google-cloud-sdk: fix searching for cloud_sql_proxy on the PATH (#114488)

'gcloud sql connect' command allows to connect to a CloudSQL instance from a local machine. In order to do so, it starts local 'cloud_sdk_proxy' instance. google-cloud-sdk expects to find one in SDK root (installed by 'gcloud components') or on the PATH, if SDK is not correctly installed ('.install' directory is missing). Since google-cloud-sdk on NixOS is properly installed 'gcloud sql connect' never looks for 'cloud_sql_proxy' on the PATH and simply doesn't work at all. The patch slightly modifies the check by looking not only for '.install' directory, but for actual 'cloud_sql_proxy' binary before falling back to the search on the PATH. With this patch it's now possible to use 'gcloud sql connect' on NixOS, provided that 'cloud_sql_proxy' is available either in user or system enviroment (available in nixpkgs).

commitd6876bc87971f3ad66ee1e3e7f773f6f6a2fcb3e authorPavel Borzenkov <pavel@borzenkov.net> dateSun 28 Feb 2021, 15:05 (6 years ago) parent5a0fc99
2 files changed+38
pkgs/tools/admin/google-cloud-sdk/cloud_sql_proxy_path.patch+36 pkgs/tools/admin/google-cloud-sdk/default.nix+2
pkgs/tools/admin/google-cloud-sdk/cloud_sql_proxy_path.patchnew file+36
@@ -0,0 +1,36 @@
1+diff --git a/lib/googlecloudsdk/api_lib/sql/instances.py b/lib/googlecloudsdk/api_lib/sql/instances.py
2+index 0d88ffe..814a436 100644
3+--- a/lib/googlecloudsdk/api_lib/sql/instances.py
4++++ b/lib/googlecloudsdk/api_lib/sql/instances.py
5+@@ -86,18 +86,19 @@ def GetRegionFromZone(gce_zone):
6+ def _GetCloudSqlProxyPath():
7+ """Determines the path to the cloud_sql_proxy binary."""
8+ sdk_bin_path = config.Paths().sdk_bin_path
9+- if not sdk_bin_path:
10+- # Check if cloud_sql_proxy is located on the PATH.
11+- proxy_path = file_utils.FindExecutableOnPath('cloud_sql_proxy')
12+- if proxy_path:
13+- log.debug(
14+- 'Using cloud_sql_proxy found at [{path}]'.format(path=proxy_path))
15+- return proxy_path
16+- else:
17+- raise exceptions.ToolException(
18+- 'A Cloud SQL Proxy SDK root could not be found. Please check your '
19+- 'installation.')
20+- return os.path.join(sdk_bin_path, 'cloud_sql_proxy')
21++ if sdk_bin_path and os.path.isfile(os.path.join(sdk_bin_path, 'cloud_sql_proxy')):
22++ return os.path.join(sdk_bin_path, 'cloud_sql_proxy')
23++
24++ # Check if cloud_sql_proxy is located on the PATH.
25++ proxy_path = file_utils.FindExecutableOnPath('cloud_sql_proxy')
26++ if proxy_path:
27++ log.debug(
28++ 'Using cloud_sql_proxy found at [{path}]'.format(path=proxy_path))
29++ return proxy_path
30++
31++ raise exceptions.ToolException(
32++ 'A Cloud SQL Proxy SDK root could not be found. Please check your '
33++ 'installation.')
34+
35+
36+ def _RaiseProxyError(error_msg=None):
pkgs/tools/admin/google-cloud-sdk/default.nix+2
@@ -45,6 +45,8 @@ in stdenv.mkDerivation rec {
4545 ./gcloud-path.patch
4646 # Disable checking for updates for the package
4747 ./gsutil-disable-updates.patch
48+ # Try to use cloud_sql_proxy from SDK only if it actually exists, otherwise, search for one in PATH
49+ ./cloud_sql_proxy_path.patch
4850 ];
4951
5052 installPhase = ''