You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+9-1Lines changed: 9 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@ cloud_sql_proxy takes a few arguments to configure what instances to connect to
19
19
optional `-fuse_tmp` flag can specify where to place temporary files. The
20
20
directory indicated by `-dir` is mounted.
21
21
*`-instances="project1:region:instance1,project3:region:instance1"`: A comma-separated list
22
-
of instances to open inside `-dir`. Also supports exposing a tcp port instead of using Unix Domain Sockets; see examples below.
22
+
of instances to open inside `-dir`. Also supports exposing a tcp port and renaming the default Unix Domain Sockets; see examples below.
23
23
Same list can be provided via INSTANCES environment variable, in case when both are provided - proxy will use command line flag.
24
24
*`-instances_metadata=metadata_key`: Usable on [GCE](https://cloud.google.com/compute/docs/quickstart) only. The given [GCE metadata](https://cloud.google.com/compute/docs/metadata) key will be
25
25
polled for a list of instances to open in `-dir`. The metadata key is relative from `computeMetadata/v1/`. The format for the value is the same as the 'instances' flag. A hanging-poll strategy is used, meaning that changes to
returninstanceConfig{}, fmt.Errorf("invalid instance argument: must be either form - `<instance_connection_string>` or `<instance_connection_string>=<options>`; invalid arg was %q", instance)
227
+
}
228
+
// Parse the instance connection name - everything before the "=".
229
+
ret.Instance=args[0]
230
+
proj, _, name:=util.SplitName(ret.Instance)
231
+
ifproj==""||name=="" {
232
+
returninstanceConfig{}, fmt.Errorf("invalid instance connection string: must be in the form `project:region:instance-name`; invalid name was %q", args[0])
233
+
}
234
+
iflen(args) ==1 {
235
+
// Default to listening via unix socket in specified directory
236
+
ret.Network="unix"
237
+
ret.Address=filepath.Join(dir, instance)
238
+
} else {
239
+
// Parse the instance options if present.
240
+
opts:=strings.SplitN(args[1], ":", 2)
241
+
iflen(opts) !=2 {
242
+
returninstanceConfig{}, fmt.Errorf("invalid instance options: must be in the form `unix:/path/to/socket`, `tcp:port`, `tcp:host:port`; invalid option was %q", strings.Join(opts, ":"))
243
+
}
244
+
ret.Network=opts[0]
245
+
varerrerror
246
+
ifret.Network=="unix" {
247
+
ifstrings.HasPrefix(opts[1], "/") {
248
+
ret.Address=opts[1] // Root path.
249
+
} else {
250
+
ret.Address=filepath.Join(dir, opts[1])
239
251
}
240
-
ret.Address=fmt.Sprintf("%s:%s", addr, spl[1])
241
-
case3:
242
-
// User provided a host and port; use that.
243
-
ret.Network=spl[0]
244
-
ret.Address=fmt.Sprintf("%s:%s", spl[1], spl[2])
252
+
} else {
253
+
ret.Address, err=parseTCPOpts(opts[0], opts[1])
245
254
}
246
-
} else {
247
-
sql, err:=sqladmin.New(cl)
248
255
iferr!=nil {
249
256
returninstanceConfig{}, err
250
257
}
251
-
sql.BasePath=*host
252
-
ret.Instance=instance
253
-
// Default to unix socket.
254
-
ret.Network="unix"
258
+
}
255
259
256
-
proj, _, name:=util.SplitName(instance)
257
-
ifproj==""||name=="" {
258
-
returninstanceConfig{}, fmt.Errorf("invalid instance name: must be in the form `project:region:instance-name`; invalid name was %q", instance)
259
-
}
260
-
// We allow people to omit the region due to historical reasons. It'll
261
-
// fail later in the code if this isn't allowed, so just assume it's
262
-
// allowed until we actually need the region in this API call.
263
-
in, err:=sql.Instances.Get(proj, name).Do()
264
-
iferr!=nil {
260
+
// Use the SQL Admin API to verify compatibility with the instance.
261
+
sql, err:=sqladmin.New(cl)
262
+
iferr!=nil {
263
+
returninstanceConfig{}, err
264
+
}
265
+
sql.BasePath=*host
266
+
inst, err:=sql.Instances.Get(proj, name).Do()
267
+
iferr!=nil {
268
+
returninstanceConfig{}, err
269
+
}
270
+
ifinst.BackendType=="FIRST_GEN" {
271
+
logging.Errorf("WARNING: proxy client does not support first generation Cloud SQL instances.")
272
+
returninstanceConfig{}, fmt.Errorf("%q is a first generation instance", instance)
273
+
}
274
+
// Postgres instances use a special suffix on the unix socket.
275
+
// See https://www.postgresql.org/docs/11/runtime-config-connection.html
0 commit comments