From ee63b7dfa77227ca0dc1dbb3d224285c2778e966 Mon Sep 17 00:00:00 2001 From: Omar Polo Date: Mon, 22 Jun 2026 11:08:13 +0000 Subject: [PATCH] accept project:region:instance for GCP cloud db instances --- mysql/mysqlconn/conn.go | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/mysql/mysqlconn/conn.go b/mysql/mysqlconn/conn.go index 000c462..be45bcb 100644 --- a/mysql/mysqlconn/conn.go +++ b/mysql/mysqlconn/conn.go @@ -72,22 +72,31 @@ func ParseConnConfig(proxy bool, config map[string]string) (ConnConfig, error) { Port: "3306", } - if location, ok := config["location"]; ok && location != "" { - if err := parseURI(location, &cc); err != nil { - return cc, fmt.Errorf("parsing location URI: %w", err) + if proxy { + _, host, ok := strings.Cut(config["location"], "://") + if !ok { + return cc, fmt.Errorf("failed to parse location URI: expected protocol://identifier") + } + cc.Host = host + } else { + if location, ok := config["location"]; ok && location != "" { + if err := parseURI(location, &cc); err != nil { + return cc, fmt.Errorf("parsing location URI: %w", err) + } } - } - if v := config["host"]; v != "" { - cc.Host = v - } - if v := config["port"]; v != "" { - p, err := strconv.Atoi(v) - if err != nil || p < 1 || p > 65535 { - return cc, fmt.Errorf("invalid port %q: must be an integer between 1 and 65535", v) + if v := config["host"]; v != "" { + cc.Host = v + } + if v := config["port"]; v != "" { + p, err := strconv.Atoi(v) + if err != nil || p < 1 || p > 65535 { + return cc, fmt.Errorf("invalid port %q: must be an integer between 1 and 65535", v) + } + cc.Port = v } - cc.Port = v } + if v := config["username"]; v != "" { cc.Username = v }