-
Notifications
You must be signed in to change notification settings - Fork 352
Expand file tree
/
Copy pathoptions.go
More file actions
139 lines (121 loc) · 3.89 KB
/
options.go
File metadata and controls
139 lines (121 loc) · 3.89 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// 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(mc uint64) Option {
return func(c *Command) {
c.conf.MaxConnections = mc
}
}
// 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
}
}
// WithProxyV1Compatibility enables legacy behavior of v1 and will print
// out "Ready for new connections" when the proxy starts.
func WithProxyV1Compatibility() Option {
return func(c *Command) {
c.conf.ProxyV1Compatibility = true
}
}
// WithProxyV1LogDebugStdout enables legacy behavior of v1 and will print
// debug/info logs to stdout instead of stderr.
func WithProxyV1LogDebugStdout() Option {
return func(c *Command) {
c.conf.LogDebugStdout = true
}
}
// WithProxyV1Projects enables legacy behavior of v1 and will connect to
// all Second Generation instances in the provided projects.
func WithProxyV1Projects(projects []string) Option {
return func(c *Command) {
c.conf.Projects = projects
}
}
// WithProxyV1Verbose enables legacy behavior of v1 and will set
// the debug-logs flag on the v2 proxy.
func WithProxyV1Verbose(v bool) Option {
return func(c *Command) {
c.conf.DebugLogs = v
}
}
// 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
}
}
// WithConnRefuseNotify configures the Proxy to call the provided function when
// a connection is refused. The notification function is run in a goroutine.
func WithConnRefuseNotify(n func()) Option {
return func(c *Command) {
c.connRefuseNotify = n
}
}