From d6876bc87971f3ad66ee1e3e7f773f6f6a2fcb3e Mon Sep 17 00:00:00 2001 From: Pavel Borzenkov Date: Sun, 28 Feb 2021 15:05:26 +0300 Subject: 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). --- .../google-cloud-sdk/cloud_sql_proxy_path.patch | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 pkgs/tools/admin/google-cloud-sdk/cloud_sql_proxy_path.patch (limited to 'pkgs/tools/admin/google-cloud-sdk/cloud_sql_proxy_path.patch') diff --git a/pkgs/tools/admin/google-cloud-sdk/cloud_sql_proxy_path.patch b/pkgs/tools/admin/google-cloud-sdk/cloud_sql_proxy_path.patch new file mode 100644 index 00000000000..aec4be2ec19 --- /dev/null +++ b/pkgs/tools/admin/google-cloud-sdk/cloud_sql_proxy_path.patch @@ -0,0 +1,36 @@ +diff --git a/lib/googlecloudsdk/api_lib/sql/instances.py b/lib/googlecloudsdk/api_lib/sql/instances.py +index 0d88ffe..814a436 100644 +--- a/lib/googlecloudsdk/api_lib/sql/instances.py ++++ b/lib/googlecloudsdk/api_lib/sql/instances.py +@@ -86,18 +86,19 @@ def GetRegionFromZone(gce_zone): + def _GetCloudSqlProxyPath(): + """Determines the path to the cloud_sql_proxy binary.""" + sdk_bin_path = config.Paths().sdk_bin_path +- if not sdk_bin_path: +- # Check if cloud_sql_proxy is located on the PATH. +- proxy_path = file_utils.FindExecutableOnPath('cloud_sql_proxy') +- if proxy_path: +- log.debug( +- 'Using cloud_sql_proxy found at [{path}]'.format(path=proxy_path)) +- return proxy_path +- else: +- raise exceptions.ToolException( +- 'A Cloud SQL Proxy SDK root could not be found. Please check your ' +- 'installation.') +- return os.path.join(sdk_bin_path, 'cloud_sql_proxy') ++ if sdk_bin_path and os.path.isfile(os.path.join(sdk_bin_path, 'cloud_sql_proxy')): ++ return os.path.join(sdk_bin_path, 'cloud_sql_proxy') ++ ++ # Check if cloud_sql_proxy is located on the PATH. ++ proxy_path = file_utils.FindExecutableOnPath('cloud_sql_proxy') ++ if proxy_path: ++ log.debug( ++ 'Using cloud_sql_proxy found at [{path}]'.format(path=proxy_path)) ++ return proxy_path ++ ++ raise exceptions.ToolException( ++ 'A Cloud SQL Proxy SDK root could not be found. Please check your ' ++ 'installation.') + + + def _RaiseProxyError(error_msg=None): -- cgit 1.4.1