-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
_cloud_sql_proxy
194 lines (188 loc) · 8.78 KB
/
_cloud_sql_proxy
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#compdef cloud_sql_proxy
# -----------------------------------------------------------------------------
# The BSD-3-Clause License
#
# Copyright (c) 2016, Koichi Shiraishi
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# * Neither the name of que nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
# -----------------------------------------------------------------------------
#
# The Cloud SQL Proxy allows simple, secure connectivity to Google Cloud SQL. It
# is a long-running process that opens local sockets (either TCP or Unix sockets)
# according to the parameters passed to it. A local application connects to a
# Cloud SQL instance by using the corresponding socket.
#
#
# Authorization:
# * On Google Compute Engine, the default service account is used.
# The Cloud SQL API must be enabled for the VM.
#
# * When the gcloud command-line tool is installed on the local machine, the
# "active account" is used for authentication. Run 'gcloud auth list' to see
# which accounts are installed on your local machine and
# 'gcloud config list account' to view the active account.
#
# * To configure the proxy using a service account, pass the -credential_file
# parameter or set the GOOGLE_APPLICATION_CREDENTIALS environment variable.
# This will override gcloud or GCE (Google Compute Engine) credentials,
# if they exist.
#
# General:
# -quiet
# Disable log messages (e.g. when new connections are established).
# WARNING: this option disables ALL logging output (including connection
# errors), which will likely make debugging difficult. The -quiet flag takes
# precedence over the -verbose flag.
# -verbose
# When explicitly set to false, disable log messages that are not errors nor
# first-time startup messages (e.g. when new connections are established).
#
# Connection:
# -instances
# To connect to a specific list of instances, set the instances parameter
# to a comma-separated list of instance connection strings. For example:
#
# -instances=my-project:my-region:my-instance
#
# For connectivity over TCP, you must specify a tcp port as part of the
# instance string. For example, the following example opens a loopback TCP
# socket on port 3306, which will be proxied to connect to the instance
# 'my-instance' in project 'my-project':
#
# -instances=my-project:my-region:my-instance=tcp:3306
#
# When connecting over TCP, the -instances parameter is required.
#
# -instances_metadata
# When running on GCE (Google Compute Engine) you can avoid the need to
# specify the list of instances on the command line by using the Metadata
# server. This parameter specifies a path to a metadata value which is then
# interpreted as a list of instances in the exact same way as the -instances
# parameter. Updates to the metadata value will be observed and acted on by
# the Proxy.
#
# -projects
# To direct the proxy to allow connections to all instances in specific
# projects, set the projects parameter:
#
# -projects=my-project
#
# -fuse
# If your local environment has FUSE installed, you can specify the -fuse
# flag to avoid the requirement to specify instances in advance. With FUSE,
# any attempts to open a Unix socket in the directory specified by -dir
# automatically creates that socket and connects to the corresponding
# instance.
#
# -dir
# When using Unix sockets (the default for systems which support them), the
# Proxy places the sockets in the directory specified by the -dir parameter.
#
#
# Automatic instance discovery:
# If the Google Cloud SQL is installed on the local machine and no instance
# connection flags are specified, the proxy connects to all instances in the
# gcloud tool's active project. Run 'gcloud config list project' to
# display the active project.
#
#
# Information for all flags:
# -check_region
# If specified, the 'region' portion of the connection string is required for
# Unix socket-based connections.
#
# -credential_file
# If provided, this json file will be used to retrieve Service Account credentials.
# You may set the GOOGLE_APPLICATION_CREDENTIALS environment variable for the same effect.
#
# -dir
# Directory to use for placing Unix sockets representing database instances
#
# -fuse
# Mount a directory at 'dir' using FUSE for accessing instances. Note that the
# directory at 'dir' must be empty before this program is started.
#
# -fuse_tmp
# Used as a temporary directory if -fuse is set. Note that files in this directory
# can be removed automatically by this program.
#
# -instances
# Comma-separated list of fully qualified instances (project:region:name)
# to connect to. If the name has the suffix '=tcp:port', a TCP server is opened
# on the specified port to proxy to that instance. Otherwise, one socket file per
# instance is opened in 'dir'. Not compatible with -fuse
#
# -instances_metadata
# If provided, it is treated as a path to a metadata value which
# is polled for a comma-separated list of instances to connect to. For example,
# to use the instance metadata value named 'cloud-sql-instances' you would
# provide 'instance/attributes/cloud-sql-instances'. Not compatible with -fuse
#
# -projects
# Open sockets for each Cloud SQL Instance in the projects specified
# (comma-separated list)
#
# -quiet
# Disable log messages
#
# -refresh_config_throttle
# If set, this flag specifies the amount of forced sleep between successive API calls in order to protect client API quota. Minimum allowed value is 1s
#
# -token
# When set, the proxy uses this Bearer token for authorization.
#
# -verbose
# If false, verbose output such as information about when connections are created/closed without error are suppressed
#
# -version
# Print the version of the proxy and exit
#
# -----------------------------------------------------------------------------
function _cloud_sql_proxy() {
local context curcontext=$curcontext state line ret=1
declare -A opt_args
_arguments -C \
"-check_region[If specified, the 'region' portion of the connection string is required for Unix socket-based connections]" \
"-fuse[Mount a directory at 'dir' using FUSE for accessing instances]" \
'-credential_file[If provided, this json file will be used to retrieve Service Account credentials]' \
'-dir[Directory to use for placing Unix sockets representing database instances]' \
'-fuse_tmp[Used as a temporary directory if -fuse is set]' \
'-instances[To connect to a specific list of instances, set the instances parameter to a comma-separated list of instance connection strings]' \
'-instances_metadata[When running on GCE you can avoid the need to specify the list of instances on the command line by using the Metadata server]' \
'-projects[Open sockets for each Cloud SQL Instance in the projects specified]' \
'-quiet[Disable log messages]' \
'-refresh_config_throttle[If set, this flag specifies the amount of forced sleep between successive API calls in order to protect client API quota]' \
'-token[When set, the proxy uses this Bearer token for authorization]' \
'-verbose[If false, verbose output such as information about when connections are created/closed without error are suppressed]' \
'-version[Print the version of the proxy and exit]' \
'*:: :->args' \
&& ret=0
return ret
}
_cloud_sql_proxy "$*"
# vim:ft=zsh:et:sts=2:sw=2