-
Notifications
You must be signed in to change notification settings - Fork 344
/
options.go
99 lines (86 loc) · 2.74 KB
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package cmd
import "github.com/GoogleCloudPlatform/cloud-sql-proxy/v2/cloudsql"
// Option is a function that configures a Command.
type Option func(*Command)
// WithLogger overrides the default logger.
func WithLogger(l cloudsql.Logger) Option {
return func(c *Command) {
c.logger = l
}
}
// WithDialer configures the Command to use the provided dialer to connect to
// Cloud SQL instances.
func WithDialer(d cloudsql.Dialer) Option {
return func(c *Command) {
c.dialer = d
}
}
// WithFuseDir mounts a directory at the path using FUSE to access Cloud SQL
// instances.
func WithFuseDir(dir string) Option {
return func(c *Command) {
c.conf.FUSEDir = dir
}
}
// WithFuseTempDir sets the temp directory where Unix sockets are created with
// FUSE
func WithFuseTempDir(dir string) Option {
return func(c *Command) {
c.conf.FUSETempDir = dir
}
}
// WithMaxConnections sets the maximum allowed number of connections. Default
// is no limit.
func WithMaxConnections(max uint64) Option {
return func(c *Command) {
c.conf.MaxConnections = max
}
}
// WithUserAgent sets additional user agents for Admin API tracking and should
// be a space separated list of additional user agents, e.g.
// cloud-sql-proxy-operator/0.0.1,other-agent/1.0.0
func WithUserAgent(agent string) Option {
return func(c *Command) {
c.conf.OtherUserAgents = agent
}
}
// WithAutoIP enables legacy behavior of v1 and will try to connect to first IP
// address returned by the SQL Admin API. In most cases, this flag should not
// be used. Prefer default of public IP or use --private-ip instead.`
func WithAutoIP() Option {
return func(c *Command) {
c.conf.AutoIP = true
}
}
// WithQuietLogging configures the Proxy to log error messages only.
func WithQuietLogging() Option {
return func(c *Command) {
c.conf.Quiet = true
}
}
// WithDebugLogging configures the Proxy to log debug level messages.
func WithDebugLogging() Option {
return func(c *Command) {
c.conf.DebugLogs = true
}
}
// WithLazyRefresh configures the Proxy to refresh connection info on an
// as-needed basis when the cached copy has expired.
func WithLazyRefresh() Option {
return func(c *Command) {
c.conf.LazyRefresh = true
}
}