planetscale 0.3.1 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (368) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +9 -1
  3. data/.github/workflows/gem-push.yml +9 -2
  4. data/.licenses/go/github.com/matoous/go-nanoid/v2.dep.yml +34 -0
  5. data/.licenses/go/github.com/planetscale/planetscale-go/planetscale.dep.yml +1 -1
  6. data/.licenses/go/github.com/planetscale/sql-proxy/proxy.dep.yml +1 -1
  7. data/.licenses/go/go.uber.org/zap/buffer.dep.yml +1 -1
  8. data/.licenses/go/go.uber.org/zap/internal/bufferpool.dep.yml +1 -1
  9. data/.licenses/go/go.uber.org/zap/internal/color.dep.yml +1 -1
  10. data/.licenses/go/go.uber.org/zap/internal/exit.dep.yml +1 -1
  11. data/.licenses/go/go.uber.org/zap/zapcore.dep.yml +1 -1
  12. data/.licenses/go/go.uber.org/zap.dep.yml +1 -1
  13. data/README.md +2 -0
  14. data/controller.go +21 -36
  15. data/go.mod +4 -3
  16. data/go.sum +32 -18
  17. data/lib/planetscale/version.rb +1 -1
  18. data/lib/planetscale.rb +2 -3
  19. data/planetscale.gemspec +1 -1
  20. data/proxy/planetscale-darwin.h +1 -1
  21. data/proxy/planetscale-darwin.so +0 -0
  22. data/proxy/planetscale-linux.h +1 -1
  23. data/proxy/planetscale-linux.so +0 -0
  24. data/proxy.go +1 -5
  25. metadata +3 -345
  26. data/vendor/github.com/armon/circbuf/.gitignore +0 -22
  27. data/vendor/github.com/armon/circbuf/LICENSE +0 -20
  28. data/vendor/github.com/armon/circbuf/README.md +0 -28
  29. data/vendor/github.com/armon/circbuf/circbuf.go +0 -92
  30. data/vendor/github.com/armon/circbuf/go.mod +0 -1
  31. data/vendor/github.com/golang/protobuf/AUTHORS +0 -3
  32. data/vendor/github.com/golang/protobuf/CONTRIBUTORS +0 -3
  33. data/vendor/github.com/golang/protobuf/LICENSE +0 -28
  34. data/vendor/github.com/golang/protobuf/proto/buffer.go +0 -324
  35. data/vendor/github.com/golang/protobuf/proto/defaults.go +0 -63
  36. data/vendor/github.com/golang/protobuf/proto/deprecated.go +0 -113
  37. data/vendor/github.com/golang/protobuf/proto/discard.go +0 -58
  38. data/vendor/github.com/golang/protobuf/proto/extensions.go +0 -356
  39. data/vendor/github.com/golang/protobuf/proto/properties.go +0 -306
  40. data/vendor/github.com/golang/protobuf/proto/proto.go +0 -167
  41. data/vendor/github.com/golang/protobuf/proto/registry.go +0 -317
  42. data/vendor/github.com/golang/protobuf/proto/text_decode.go +0 -801
  43. data/vendor/github.com/golang/protobuf/proto/text_encode.go +0 -560
  44. data/vendor/github.com/golang/protobuf/proto/wire.go +0 -78
  45. data/vendor/github.com/golang/protobuf/proto/wrappers.go +0 -34
  46. data/vendor/github.com/gorilla/mux/AUTHORS +0 -8
  47. data/vendor/github.com/gorilla/mux/LICENSE +0 -27
  48. data/vendor/github.com/gorilla/mux/README.md +0 -805
  49. data/vendor/github.com/gorilla/mux/doc.go +0 -306
  50. data/vendor/github.com/gorilla/mux/go.mod +0 -3
  51. data/vendor/github.com/gorilla/mux/middleware.go +0 -74
  52. data/vendor/github.com/gorilla/mux/mux.go +0 -606
  53. data/vendor/github.com/gorilla/mux/regexp.go +0 -388
  54. data/vendor/github.com/gorilla/mux/route.go +0 -736
  55. data/vendor/github.com/gorilla/mux/test_helpers.go +0 -19
  56. data/vendor/github.com/hashicorp/go-cleanhttp/LICENSE +0 -363
  57. data/vendor/github.com/hashicorp/go-cleanhttp/README.md +0 -30
  58. data/vendor/github.com/hashicorp/go-cleanhttp/cleanhttp.go +0 -58
  59. data/vendor/github.com/hashicorp/go-cleanhttp/doc.go +0 -20
  60. data/vendor/github.com/hashicorp/go-cleanhttp/go.mod +0 -3
  61. data/vendor/github.com/hashicorp/go-cleanhttp/handlers.go +0 -48
  62. data/vendor/github.com/mitchellh/go-homedir/LICENSE +0 -21
  63. data/vendor/github.com/mitchellh/go-homedir/README.md +0 -14
  64. data/vendor/github.com/mitchellh/go-homedir/go.mod +0 -1
  65. data/vendor/github.com/mitchellh/go-homedir/homedir.go +0 -167
  66. data/vendor/github.com/pkg/errors/.gitignore +0 -24
  67. data/vendor/github.com/pkg/errors/.travis.yml +0 -10
  68. data/vendor/github.com/pkg/errors/LICENSE +0 -23
  69. data/vendor/github.com/pkg/errors/Makefile +0 -44
  70. data/vendor/github.com/pkg/errors/README.md +0 -59
  71. data/vendor/github.com/pkg/errors/appveyor.yml +0 -32
  72. data/vendor/github.com/pkg/errors/errors.go +0 -288
  73. data/vendor/github.com/pkg/errors/go113.go +0 -38
  74. data/vendor/github.com/pkg/errors/stack.go +0 -177
  75. data/vendor/github.com/planetscale/planetscale-go/LICENSE +0 -202
  76. data/vendor/github.com/planetscale/planetscale-go/planetscale/audit_logs.go +0 -136
  77. data/vendor/github.com/planetscale/planetscale-go/planetscale/backups.go +0 -139
  78. data/vendor/github.com/planetscale/planetscale-go/planetscale/branches.go +0 -252
  79. data/vendor/github.com/planetscale/planetscale-go/planetscale/certs.go +0 -166
  80. data/vendor/github.com/planetscale/planetscale-go/planetscale/client.go +0 -312
  81. data/vendor/github.com/planetscale/planetscale-go/planetscale/databases.go +0 -133
  82. data/vendor/github.com/planetscale/planetscale-go/planetscale/deploy_requests.go +0 -368
  83. data/vendor/github.com/planetscale/planetscale-go/planetscale/organizations.go +0 -103
  84. data/vendor/github.com/planetscale/planetscale-go/planetscale/regions.go +0 -52
  85. data/vendor/github.com/planetscale/planetscale-go/planetscale/service_tokens.go +0 -163
  86. data/vendor/github.com/planetscale/sql-proxy/LICENSE +0 -202
  87. data/vendor/github.com/planetscale/sql-proxy/proxy/client.go +0 -476
  88. data/vendor/github.com/planetscale/sql-proxy/proxy/tls_cache.go +0 -73
  89. data/vendor/go.uber.org/atomic/.codecov.yml +0 -19
  90. data/vendor/go.uber.org/atomic/.gitignore +0 -12
  91. data/vendor/go.uber.org/atomic/.travis.yml +0 -27
  92. data/vendor/go.uber.org/atomic/CHANGELOG.md +0 -76
  93. data/vendor/go.uber.org/atomic/LICENSE.txt +0 -19
  94. data/vendor/go.uber.org/atomic/Makefile +0 -78
  95. data/vendor/go.uber.org/atomic/README.md +0 -63
  96. data/vendor/go.uber.org/atomic/bool.go +0 -81
  97. data/vendor/go.uber.org/atomic/bool_ext.go +0 -53
  98. data/vendor/go.uber.org/atomic/doc.go +0 -23
  99. data/vendor/go.uber.org/atomic/duration.go +0 -82
  100. data/vendor/go.uber.org/atomic/duration_ext.go +0 -40
  101. data/vendor/go.uber.org/atomic/error.go +0 -51
  102. data/vendor/go.uber.org/atomic/error_ext.go +0 -39
  103. data/vendor/go.uber.org/atomic/float64.go +0 -76
  104. data/vendor/go.uber.org/atomic/float64_ext.go +0 -47
  105. data/vendor/go.uber.org/atomic/gen.go +0 -26
  106. data/vendor/go.uber.org/atomic/go.mod +0 -8
  107. data/vendor/go.uber.org/atomic/go.sum +0 -9
  108. data/vendor/go.uber.org/atomic/int32.go +0 -102
  109. data/vendor/go.uber.org/atomic/int64.go +0 -102
  110. data/vendor/go.uber.org/atomic/nocmp.go +0 -35
  111. data/vendor/go.uber.org/atomic/string.go +0 -54
  112. data/vendor/go.uber.org/atomic/string_ext.go +0 -43
  113. data/vendor/go.uber.org/atomic/uint32.go +0 -102
  114. data/vendor/go.uber.org/atomic/uint64.go +0 -102
  115. data/vendor/go.uber.org/atomic/value.go +0 -31
  116. data/vendor/go.uber.org/multierr/.codecov.yml +0 -15
  117. data/vendor/go.uber.org/multierr/.gitignore +0 -4
  118. data/vendor/go.uber.org/multierr/.travis.yml +0 -23
  119. data/vendor/go.uber.org/multierr/CHANGELOG.md +0 -60
  120. data/vendor/go.uber.org/multierr/LICENSE.txt +0 -19
  121. data/vendor/go.uber.org/multierr/Makefile +0 -42
  122. data/vendor/go.uber.org/multierr/README.md +0 -23
  123. data/vendor/go.uber.org/multierr/error.go +0 -449
  124. data/vendor/go.uber.org/multierr/glide.yaml +0 -8
  125. data/vendor/go.uber.org/multierr/go.mod +0 -8
  126. data/vendor/go.uber.org/multierr/go.sum +0 -11
  127. data/vendor/go.uber.org/multierr/go113.go +0 -52
  128. data/vendor/go.uber.org/zap/.codecov.yml +0 -17
  129. data/vendor/go.uber.org/zap/.gitignore +0 -32
  130. data/vendor/go.uber.org/zap/.readme.tmpl +0 -109
  131. data/vendor/go.uber.org/zap/CHANGELOG.md +0 -492
  132. data/vendor/go.uber.org/zap/CODE_OF_CONDUCT.md +0 -75
  133. data/vendor/go.uber.org/zap/CONTRIBUTING.md +0 -75
  134. data/vendor/go.uber.org/zap/FAQ.md +0 -164
  135. data/vendor/go.uber.org/zap/LICENSE.txt +0 -19
  136. data/vendor/go.uber.org/zap/Makefile +0 -73
  137. data/vendor/go.uber.org/zap/README.md +0 -134
  138. data/vendor/go.uber.org/zap/array.go +0 -320
  139. data/vendor/go.uber.org/zap/buffer/buffer.go +0 -141
  140. data/vendor/go.uber.org/zap/buffer/pool.go +0 -49
  141. data/vendor/go.uber.org/zap/checklicense.sh +0 -17
  142. data/vendor/go.uber.org/zap/config.go +0 -264
  143. data/vendor/go.uber.org/zap/doc.go +0 -113
  144. data/vendor/go.uber.org/zap/encoder.go +0 -79
  145. data/vendor/go.uber.org/zap/error.go +0 -80
  146. data/vendor/go.uber.org/zap/field.go +0 -549
  147. data/vendor/go.uber.org/zap/flag.go +0 -39
  148. data/vendor/go.uber.org/zap/glide.yaml +0 -34
  149. data/vendor/go.uber.org/zap/global.go +0 -168
  150. data/vendor/go.uber.org/zap/global_go112.go +0 -26
  151. data/vendor/go.uber.org/zap/global_prego112.go +0 -26
  152. data/vendor/go.uber.org/zap/go.mod +0 -14
  153. data/vendor/go.uber.org/zap/go.sum +0 -54
  154. data/vendor/go.uber.org/zap/http_handler.go +0 -132
  155. data/vendor/go.uber.org/zap/internal/bufferpool/bufferpool.go +0 -31
  156. data/vendor/go.uber.org/zap/internal/color/color.go +0 -44
  157. data/vendor/go.uber.org/zap/internal/exit/exit.go +0 -64
  158. data/vendor/go.uber.org/zap/level.go +0 -132
  159. data/vendor/go.uber.org/zap/logger.go +0 -348
  160. data/vendor/go.uber.org/zap/options.go +0 -148
  161. data/vendor/go.uber.org/zap/sink.go +0 -161
  162. data/vendor/go.uber.org/zap/stacktrace.go +0 -85
  163. data/vendor/go.uber.org/zap/sugar.go +0 -315
  164. data/vendor/go.uber.org/zap/time.go +0 -27
  165. data/vendor/go.uber.org/zap/writer.go +0 -99
  166. data/vendor/go.uber.org/zap/zapcore/buffered_write_syncer.go +0 -188
  167. data/vendor/go.uber.org/zap/zapcore/clock.go +0 -50
  168. data/vendor/go.uber.org/zap/zapcore/console_encoder.go +0 -161
  169. data/vendor/go.uber.org/zap/zapcore/core.go +0 -113
  170. data/vendor/go.uber.org/zap/zapcore/doc.go +0 -24
  171. data/vendor/go.uber.org/zap/zapcore/encoder.go +0 -443
  172. data/vendor/go.uber.org/zap/zapcore/entry.go +0 -264
  173. data/vendor/go.uber.org/zap/zapcore/error.go +0 -132
  174. data/vendor/go.uber.org/zap/zapcore/field.go +0 -233
  175. data/vendor/go.uber.org/zap/zapcore/hook.go +0 -68
  176. data/vendor/go.uber.org/zap/zapcore/increase_level.go +0 -66
  177. data/vendor/go.uber.org/zap/zapcore/json_encoder.go +0 -534
  178. data/vendor/go.uber.org/zap/zapcore/level.go +0 -175
  179. data/vendor/go.uber.org/zap/zapcore/level_strings.go +0 -46
  180. data/vendor/go.uber.org/zap/zapcore/marshaler.go +0 -61
  181. data/vendor/go.uber.org/zap/zapcore/memory_encoder.go +0 -179
  182. data/vendor/go.uber.org/zap/zapcore/sampler.go +0 -208
  183. data/vendor/go.uber.org/zap/zapcore/tee.go +0 -81
  184. data/vendor/go.uber.org/zap/zapcore/write_syncer.go +0 -122
  185. data/vendor/golang.org/x/net/AUTHORS +0 -3
  186. data/vendor/golang.org/x/net/CONTRIBUTORS +0 -3
  187. data/vendor/golang.org/x/net/LICENSE +0 -27
  188. data/vendor/golang.org/x/net/PATENTS +0 -22
  189. data/vendor/golang.org/x/net/context/context.go +0 -56
  190. data/vendor/golang.org/x/net/context/ctxhttp/ctxhttp.go +0 -71
  191. data/vendor/golang.org/x/net/context/go17.go +0 -73
  192. data/vendor/golang.org/x/net/context/go19.go +0 -21
  193. data/vendor/golang.org/x/net/context/pre_go17.go +0 -301
  194. data/vendor/golang.org/x/net/context/pre_go19.go +0 -110
  195. data/vendor/golang.org/x/oauth2/.travis.yml +0 -13
  196. data/vendor/golang.org/x/oauth2/AUTHORS +0 -3
  197. data/vendor/golang.org/x/oauth2/CONTRIBUTING.md +0 -26
  198. data/vendor/golang.org/x/oauth2/CONTRIBUTORS +0 -3
  199. data/vendor/golang.org/x/oauth2/LICENSE +0 -27
  200. data/vendor/golang.org/x/oauth2/README.md +0 -36
  201. data/vendor/golang.org/x/oauth2/go.mod +0 -9
  202. data/vendor/golang.org/x/oauth2/go.sum +0 -361
  203. data/vendor/golang.org/x/oauth2/internal/client_appengine.go +0 -14
  204. data/vendor/golang.org/x/oauth2/internal/doc.go +0 -6
  205. data/vendor/golang.org/x/oauth2/internal/oauth2.go +0 -37
  206. data/vendor/golang.org/x/oauth2/internal/token.go +0 -294
  207. data/vendor/golang.org/x/oauth2/internal/transport.go +0 -33
  208. data/vendor/golang.org/x/oauth2/oauth2.go +0 -381
  209. data/vendor/golang.org/x/oauth2/token.go +0 -178
  210. data/vendor/golang.org/x/oauth2/transport.go +0 -89
  211. data/vendor/google.golang.org/appengine/LICENSE +0 -202
  212. data/vendor/google.golang.org/appengine/internal/api.go +0 -678
  213. data/vendor/google.golang.org/appengine/internal/api_classic.go +0 -169
  214. data/vendor/google.golang.org/appengine/internal/api_common.go +0 -123
  215. data/vendor/google.golang.org/appengine/internal/app_id.go +0 -28
  216. data/vendor/google.golang.org/appengine/internal/base/api_base.pb.go +0 -308
  217. data/vendor/google.golang.org/appengine/internal/base/api_base.proto +0 -33
  218. data/vendor/google.golang.org/appengine/internal/datastore/datastore_v3.pb.go +0 -4367
  219. data/vendor/google.golang.org/appengine/internal/datastore/datastore_v3.proto +0 -551
  220. data/vendor/google.golang.org/appengine/internal/identity.go +0 -55
  221. data/vendor/google.golang.org/appengine/internal/identity_classic.go +0 -61
  222. data/vendor/google.golang.org/appengine/internal/identity_flex.go +0 -11
  223. data/vendor/google.golang.org/appengine/internal/identity_vm.go +0 -134
  224. data/vendor/google.golang.org/appengine/internal/internal.go +0 -110
  225. data/vendor/google.golang.org/appengine/internal/log/log_service.pb.go +0 -1313
  226. data/vendor/google.golang.org/appengine/internal/log/log_service.proto +0 -150
  227. data/vendor/google.golang.org/appengine/internal/main.go +0 -16
  228. data/vendor/google.golang.org/appengine/internal/main_common.go +0 -7
  229. data/vendor/google.golang.org/appengine/internal/main_vm.go +0 -69
  230. data/vendor/google.golang.org/appengine/internal/metadata.go +0 -60
  231. data/vendor/google.golang.org/appengine/internal/net.go +0 -56
  232. data/vendor/google.golang.org/appengine/internal/regen.sh +0 -40
  233. data/vendor/google.golang.org/appengine/internal/remote_api/remote_api.pb.go +0 -361
  234. data/vendor/google.golang.org/appengine/internal/remote_api/remote_api.proto +0 -44
  235. data/vendor/google.golang.org/appengine/internal/transaction.go +0 -115
  236. data/vendor/google.golang.org/appengine/internal/urlfetch/urlfetch_service.pb.go +0 -527
  237. data/vendor/google.golang.org/appengine/internal/urlfetch/urlfetch_service.proto +0 -64
  238. data/vendor/google.golang.org/appengine/urlfetch/urlfetch.go +0 -210
  239. data/vendor/google.golang.org/protobuf/AUTHORS +0 -3
  240. data/vendor/google.golang.org/protobuf/CONTRIBUTORS +0 -3
  241. data/vendor/google.golang.org/protobuf/LICENSE +0 -27
  242. data/vendor/google.golang.org/protobuf/PATENTS +0 -22
  243. data/vendor/google.golang.org/protobuf/encoding/prototext/decode.go +0 -773
  244. data/vendor/google.golang.org/protobuf/encoding/prototext/doc.go +0 -7
  245. data/vendor/google.golang.org/protobuf/encoding/prototext/encode.go +0 -371
  246. data/vendor/google.golang.org/protobuf/encoding/protowire/wire.go +0 -538
  247. data/vendor/google.golang.org/protobuf/internal/descfmt/stringer.go +0 -318
  248. data/vendor/google.golang.org/protobuf/internal/descopts/options.go +0 -29
  249. data/vendor/google.golang.org/protobuf/internal/detrand/rand.go +0 -69
  250. data/vendor/google.golang.org/protobuf/internal/encoding/defval/default.go +0 -213
  251. data/vendor/google.golang.org/protobuf/internal/encoding/messageset/messageset.go +0 -241
  252. data/vendor/google.golang.org/protobuf/internal/encoding/tag/tag.go +0 -207
  253. data/vendor/google.golang.org/protobuf/internal/encoding/text/decode.go +0 -665
  254. data/vendor/google.golang.org/protobuf/internal/encoding/text/decode_number.go +0 -190
  255. data/vendor/google.golang.org/protobuf/internal/encoding/text/decode_string.go +0 -161
  256. data/vendor/google.golang.org/protobuf/internal/encoding/text/decode_token.go +0 -373
  257. data/vendor/google.golang.org/protobuf/internal/encoding/text/doc.go +0 -29
  258. data/vendor/google.golang.org/protobuf/internal/encoding/text/encode.go +0 -265
  259. data/vendor/google.golang.org/protobuf/internal/errors/errors.go +0 -89
  260. data/vendor/google.golang.org/protobuf/internal/errors/is_go112.go +0 -39
  261. data/vendor/google.golang.org/protobuf/internal/errors/is_go113.go +0 -12
  262. data/vendor/google.golang.org/protobuf/internal/filedesc/build.go +0 -158
  263. data/vendor/google.golang.org/protobuf/internal/filedesc/desc.go +0 -631
  264. data/vendor/google.golang.org/protobuf/internal/filedesc/desc_init.go +0 -471
  265. data/vendor/google.golang.org/protobuf/internal/filedesc/desc_lazy.go +0 -704
  266. data/vendor/google.golang.org/protobuf/internal/filedesc/desc_list.go +0 -450
  267. data/vendor/google.golang.org/protobuf/internal/filedesc/desc_list_gen.go +0 -356
  268. data/vendor/google.golang.org/protobuf/internal/filedesc/placeholder.go +0 -107
  269. data/vendor/google.golang.org/protobuf/internal/filetype/build.go +0 -297
  270. data/vendor/google.golang.org/protobuf/internal/flags/flags.go +0 -24
  271. data/vendor/google.golang.org/protobuf/internal/flags/proto_legacy_disable.go +0 -9
  272. data/vendor/google.golang.org/protobuf/internal/flags/proto_legacy_enable.go +0 -9
  273. data/vendor/google.golang.org/protobuf/internal/genid/any_gen.go +0 -34
  274. data/vendor/google.golang.org/protobuf/internal/genid/api_gen.go +0 -106
  275. data/vendor/google.golang.org/protobuf/internal/genid/descriptor_gen.go +0 -829
  276. data/vendor/google.golang.org/protobuf/internal/genid/doc.go +0 -11
  277. data/vendor/google.golang.org/protobuf/internal/genid/duration_gen.go +0 -34
  278. data/vendor/google.golang.org/protobuf/internal/genid/empty_gen.go +0 -19
  279. data/vendor/google.golang.org/protobuf/internal/genid/field_mask_gen.go +0 -31
  280. data/vendor/google.golang.org/protobuf/internal/genid/goname.go +0 -25
  281. data/vendor/google.golang.org/protobuf/internal/genid/map_entry.go +0 -16
  282. data/vendor/google.golang.org/protobuf/internal/genid/source_context_gen.go +0 -31
  283. data/vendor/google.golang.org/protobuf/internal/genid/struct_gen.go +0 -116
  284. data/vendor/google.golang.org/protobuf/internal/genid/timestamp_gen.go +0 -34
  285. data/vendor/google.golang.org/protobuf/internal/genid/type_gen.go +0 -184
  286. data/vendor/google.golang.org/protobuf/internal/genid/wrappers.go +0 -13
  287. data/vendor/google.golang.org/protobuf/internal/genid/wrappers_gen.go +0 -175
  288. data/vendor/google.golang.org/protobuf/internal/impl/api_export.go +0 -177
  289. data/vendor/google.golang.org/protobuf/internal/impl/checkinit.go +0 -141
  290. data/vendor/google.golang.org/protobuf/internal/impl/codec_extension.go +0 -223
  291. data/vendor/google.golang.org/protobuf/internal/impl/codec_field.go +0 -830
  292. data/vendor/google.golang.org/protobuf/internal/impl/codec_gen.go +0 -5637
  293. data/vendor/google.golang.org/protobuf/internal/impl/codec_map.go +0 -388
  294. data/vendor/google.golang.org/protobuf/internal/impl/codec_map_go111.go +0 -37
  295. data/vendor/google.golang.org/protobuf/internal/impl/codec_map_go112.go +0 -11
  296. data/vendor/google.golang.org/protobuf/internal/impl/codec_message.go +0 -217
  297. data/vendor/google.golang.org/protobuf/internal/impl/codec_messageset.go +0 -123
  298. data/vendor/google.golang.org/protobuf/internal/impl/codec_reflect.go +0 -209
  299. data/vendor/google.golang.org/protobuf/internal/impl/codec_tables.go +0 -557
  300. data/vendor/google.golang.org/protobuf/internal/impl/codec_unsafe.go +0 -17
  301. data/vendor/google.golang.org/protobuf/internal/impl/convert.go +0 -496
  302. data/vendor/google.golang.org/protobuf/internal/impl/convert_list.go +0 -141
  303. data/vendor/google.golang.org/protobuf/internal/impl/convert_map.go +0 -121
  304. data/vendor/google.golang.org/protobuf/internal/impl/decode.go +0 -276
  305. data/vendor/google.golang.org/protobuf/internal/impl/encode.go +0 -201
  306. data/vendor/google.golang.org/protobuf/internal/impl/enum.go +0 -21
  307. data/vendor/google.golang.org/protobuf/internal/impl/extension.go +0 -156
  308. data/vendor/google.golang.org/protobuf/internal/impl/legacy_enum.go +0 -219
  309. data/vendor/google.golang.org/protobuf/internal/impl/legacy_export.go +0 -92
  310. data/vendor/google.golang.org/protobuf/internal/impl/legacy_extension.go +0 -176
  311. data/vendor/google.golang.org/protobuf/internal/impl/legacy_file.go +0 -81
  312. data/vendor/google.golang.org/protobuf/internal/impl/legacy_message.go +0 -558
  313. data/vendor/google.golang.org/protobuf/internal/impl/merge.go +0 -176
  314. data/vendor/google.golang.org/protobuf/internal/impl/merge_gen.go +0 -209
  315. data/vendor/google.golang.org/protobuf/internal/impl/message.go +0 -276
  316. data/vendor/google.golang.org/protobuf/internal/impl/message_reflect.go +0 -465
  317. data/vendor/google.golang.org/protobuf/internal/impl/message_reflect_field.go +0 -543
  318. data/vendor/google.golang.org/protobuf/internal/impl/message_reflect_gen.go +0 -249
  319. data/vendor/google.golang.org/protobuf/internal/impl/pointer_reflect.go +0 -178
  320. data/vendor/google.golang.org/protobuf/internal/impl/pointer_unsafe.go +0 -174
  321. data/vendor/google.golang.org/protobuf/internal/impl/validate.go +0 -576
  322. data/vendor/google.golang.org/protobuf/internal/impl/weak.go +0 -74
  323. data/vendor/google.golang.org/protobuf/internal/order/order.go +0 -89
  324. data/vendor/google.golang.org/protobuf/internal/order/range.go +0 -115
  325. data/vendor/google.golang.org/protobuf/internal/pragma/pragma.go +0 -29
  326. data/vendor/google.golang.org/protobuf/internal/set/ints.go +0 -58
  327. data/vendor/google.golang.org/protobuf/internal/strs/strings.go +0 -196
  328. data/vendor/google.golang.org/protobuf/internal/strs/strings_pure.go +0 -27
  329. data/vendor/google.golang.org/protobuf/internal/strs/strings_unsafe.go +0 -94
  330. data/vendor/google.golang.org/protobuf/internal/version/version.go +0 -79
  331. data/vendor/google.golang.org/protobuf/proto/checkinit.go +0 -71
  332. data/vendor/google.golang.org/protobuf/proto/decode.go +0 -278
  333. data/vendor/google.golang.org/protobuf/proto/decode_gen.go +0 -603
  334. data/vendor/google.golang.org/protobuf/proto/doc.go +0 -94
  335. data/vendor/google.golang.org/protobuf/proto/encode.go +0 -319
  336. data/vendor/google.golang.org/protobuf/proto/encode_gen.go +0 -97
  337. data/vendor/google.golang.org/protobuf/proto/equal.go +0 -167
  338. data/vendor/google.golang.org/protobuf/proto/extension.go +0 -92
  339. data/vendor/google.golang.org/protobuf/proto/merge.go +0 -139
  340. data/vendor/google.golang.org/protobuf/proto/messageset.go +0 -93
  341. data/vendor/google.golang.org/protobuf/proto/proto.go +0 -43
  342. data/vendor/google.golang.org/protobuf/proto/proto_methods.go +0 -19
  343. data/vendor/google.golang.org/protobuf/proto/proto_reflect.go +0 -19
  344. data/vendor/google.golang.org/protobuf/proto/reset.go +0 -43
  345. data/vendor/google.golang.org/protobuf/proto/size.go +0 -97
  346. data/vendor/google.golang.org/protobuf/proto/size_gen.go +0 -55
  347. data/vendor/google.golang.org/protobuf/proto/wrappers.go +0 -29
  348. data/vendor/google.golang.org/protobuf/reflect/protodesc/desc.go +0 -276
  349. data/vendor/google.golang.org/protobuf/reflect/protodesc/desc_init.go +0 -248
  350. data/vendor/google.golang.org/protobuf/reflect/protodesc/desc_resolve.go +0 -286
  351. data/vendor/google.golang.org/protobuf/reflect/protodesc/desc_validate.go +0 -374
  352. data/vendor/google.golang.org/protobuf/reflect/protodesc/proto.go +0 -252
  353. data/vendor/google.golang.org/protobuf/reflect/protoreflect/methods.go +0 -77
  354. data/vendor/google.golang.org/protobuf/reflect/protoreflect/proto.go +0 -504
  355. data/vendor/google.golang.org/protobuf/reflect/protoreflect/source.go +0 -128
  356. data/vendor/google.golang.org/protobuf/reflect/protoreflect/source_gen.go +0 -461
  357. data/vendor/google.golang.org/protobuf/reflect/protoreflect/type.go +0 -665
  358. data/vendor/google.golang.org/protobuf/reflect/protoreflect/value.go +0 -285
  359. data/vendor/google.golang.org/protobuf/reflect/protoreflect/value_pure.go +0 -59
  360. data/vendor/google.golang.org/protobuf/reflect/protoreflect/value_union.go +0 -411
  361. data/vendor/google.golang.org/protobuf/reflect/protoreflect/value_unsafe.go +0 -98
  362. data/vendor/google.golang.org/protobuf/reflect/protoregistry/registry.go +0 -869
  363. data/vendor/google.golang.org/protobuf/runtime/protoiface/legacy.go +0 -15
  364. data/vendor/google.golang.org/protobuf/runtime/protoiface/methods.go +0 -167
  365. data/vendor/google.golang.org/protobuf/runtime/protoimpl/impl.go +0 -44
  366. data/vendor/google.golang.org/protobuf/runtime/protoimpl/version.go +0 -56
  367. data/vendor/google.golang.org/protobuf/types/descriptorpb/descriptor.pb.go +0 -4039
  368. data/vendor/modules.txt +0 -79
@@ -1,202 +0,0 @@
1
-
2
- Apache License
3
- Version 2.0, January 2004
4
- http://www.apache.org/licenses/
5
-
6
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
-
8
- 1. Definitions.
9
-
10
- "License" shall mean the terms and conditions for use, reproduction,
11
- and distribution as defined by Sections 1 through 9 of this document.
12
-
13
- "Licensor" shall mean the copyright owner or entity authorized by
14
- the copyright owner that is granting the License.
15
-
16
- "Legal Entity" shall mean the union of the acting entity and all
17
- other entities that control, are controlled by, or are under common
18
- control with that entity. For the purposes of this definition,
19
- "control" means (i) the power, direct or indirect, to cause the
20
- direction or management of such entity, whether by contract or
21
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
- outstanding shares, or (iii) beneficial ownership of such entity.
23
-
24
- "You" (or "Your") shall mean an individual or Legal Entity
25
- exercising permissions granted by this License.
26
-
27
- "Source" form shall mean the preferred form for making modifications,
28
- including but not limited to software source code, documentation
29
- source, and configuration files.
30
-
31
- "Object" form shall mean any form resulting from mechanical
32
- transformation or translation of a Source form, including but
33
- not limited to compiled object code, generated documentation,
34
- and conversions to other media types.
35
-
36
- "Work" shall mean the work of authorship, whether in Source or
37
- Object form, made available under the License, as indicated by a
38
- copyright notice that is included in or attached to the work
39
- (an example is provided in the Appendix below).
40
-
41
- "Derivative Works" shall mean any work, whether in Source or Object
42
- form, that is based on (or derived from) the Work and for which the
43
- editorial revisions, annotations, elaborations, or other modifications
44
- represent, as a whole, an original work of authorship. For the purposes
45
- of this License, Derivative Works shall not include works that remain
46
- separable from, or merely link (or bind by name) to the interfaces of,
47
- the Work and Derivative Works thereof.
48
-
49
- "Contribution" shall mean any work of authorship, including
50
- the original version of the Work and any modifications or additions
51
- to that Work or Derivative Works thereof, that is intentionally
52
- submitted to Licensor for inclusion in the Work by the copyright owner
53
- or by an individual or Legal Entity authorized to submit on behalf of
54
- the copyright owner. For the purposes of this definition, "submitted"
55
- means any form of electronic, verbal, or written communication sent
56
- to the Licensor or its representatives, including but not limited to
57
- communication on electronic mailing lists, source code control systems,
58
- and issue tracking systems that are managed by, or on behalf of, the
59
- Licensor for the purpose of discussing and improving the Work, but
60
- excluding communication that is conspicuously marked or otherwise
61
- designated in writing by the copyright owner as "Not a Contribution."
62
-
63
- "Contributor" shall mean Licensor and any individual or Legal Entity
64
- on behalf of whom a Contribution has been received by Licensor and
65
- subsequently incorporated within the Work.
66
-
67
- 2. Grant of Copyright License. Subject to the terms and conditions of
68
- this License, each Contributor hereby grants to You a perpetual,
69
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
- copyright license to reproduce, prepare Derivative Works of,
71
- publicly display, publicly perform, sublicense, and distribute the
72
- Work and such Derivative Works in Source or Object form.
73
-
74
- 3. Grant of Patent License. Subject to the terms and conditions of
75
- this License, each Contributor hereby grants to You a perpetual,
76
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
- (except as stated in this section) patent license to make, have made,
78
- use, offer to sell, sell, import, and otherwise transfer the Work,
79
- where such license applies only to those patent claims licensable
80
- by such Contributor that are necessarily infringed by their
81
- Contribution(s) alone or by combination of their Contribution(s)
82
- with the Work to which such Contribution(s) was submitted. If You
83
- institute patent litigation against any entity (including a
84
- cross-claim or counterclaim in a lawsuit) alleging that the Work
85
- or a Contribution incorporated within the Work constitutes direct
86
- or contributory patent infringement, then any patent licenses
87
- granted to You under this License for that Work shall terminate
88
- as of the date such litigation is filed.
89
-
90
- 4. Redistribution. You may reproduce and distribute copies of the
91
- Work or Derivative Works thereof in any medium, with or without
92
- modifications, and in Source or Object form, provided that You
93
- meet the following conditions:
94
-
95
- (a) You must give any other recipients of the Work or
96
- Derivative Works a copy of this License; and
97
-
98
- (b) You must cause any modified files to carry prominent notices
99
- stating that You changed the files; and
100
-
101
- (c) You must retain, in the Source form of any Derivative Works
102
- that You distribute, all copyright, patent, trademark, and
103
- attribution notices from the Source form of the Work,
104
- excluding those notices that do not pertain to any part of
105
- the Derivative Works; and
106
-
107
- (d) If the Work includes a "NOTICE" text file as part of its
108
- distribution, then any Derivative Works that You distribute must
109
- include a readable copy of the attribution notices contained
110
- within such NOTICE file, excluding those notices that do not
111
- pertain to any part of the Derivative Works, in at least one
112
- of the following places: within a NOTICE text file distributed
113
- as part of the Derivative Works; within the Source form or
114
- documentation, if provided along with the Derivative Works; or,
115
- within a display generated by the Derivative Works, if and
116
- wherever such third-party notices normally appear. The contents
117
- of the NOTICE file are for informational purposes only and
118
- do not modify the License. You may add Your own attribution
119
- notices within Derivative Works that You distribute, alongside
120
- or as an addendum to the NOTICE text from the Work, provided
121
- that such additional attribution notices cannot be construed
122
- as modifying the License.
123
-
124
- You may add Your own copyright statement to Your modifications and
125
- may provide additional or different license terms and conditions
126
- for use, reproduction, or distribution of Your modifications, or
127
- for any such Derivative Works as a whole, provided Your use,
128
- reproduction, and distribution of the Work otherwise complies with
129
- the conditions stated in this License.
130
-
131
- 5. Submission of Contributions. Unless You explicitly state otherwise,
132
- any Contribution intentionally submitted for inclusion in the Work
133
- by You to the Licensor shall be under the terms and conditions of
134
- this License, without any additional terms or conditions.
135
- Notwithstanding the above, nothing herein shall supersede or modify
136
- the terms of any separate license agreement you may have executed
137
- with Licensor regarding such Contributions.
138
-
139
- 6. Trademarks. This License does not grant permission to use the trade
140
- names, trademarks, service marks, or product names of the Licensor,
141
- except as required for reasonable and customary use in describing the
142
- origin of the Work and reproducing the content of the NOTICE file.
143
-
144
- 7. Disclaimer of Warranty. Unless required by applicable law or
145
- agreed to in writing, Licensor provides the Work (and each
146
- Contributor provides its Contributions) on an "AS IS" BASIS,
147
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
- implied, including, without limitation, any warranties or conditions
149
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
- PARTICULAR PURPOSE. You are solely responsible for determining the
151
- appropriateness of using or redistributing the Work and assume any
152
- risks associated with Your exercise of permissions under this License.
153
-
154
- 8. Limitation of Liability. In no event and under no legal theory,
155
- whether in tort (including negligence), contract, or otherwise,
156
- unless required by applicable law (such as deliberate and grossly
157
- negligent acts) or agreed to in writing, shall any Contributor be
158
- liable to You for damages, including any direct, indirect, special,
159
- incidental, or consequential damages of any character arising as a
160
- result of this License or out of the use or inability to use the
161
- Work (including but not limited to damages for loss of goodwill,
162
- work stoppage, computer failure or malfunction, or any and all
163
- other commercial damages or losses), even if such Contributor
164
- has been advised of the possibility of such damages.
165
-
166
- 9. Accepting Warranty or Additional Liability. While redistributing
167
- the Work or Derivative Works thereof, You may choose to offer,
168
- and charge a fee for, acceptance of support, warranty, indemnity,
169
- or other liability obligations and/or rights consistent with this
170
- License. However, in accepting such obligations, You may act only
171
- on Your own behalf and on Your sole responsibility, not on behalf
172
- of any other Contributor, and only if You agree to indemnify,
173
- defend, and hold each Contributor harmless for any liability
174
- incurred by, or claims asserted against, such Contributor by reason
175
- of your accepting any such warranty or additional liability.
176
-
177
- END OF TERMS AND CONDITIONS
178
-
179
- APPENDIX: How to apply the Apache License to your work.
180
-
181
- To apply the Apache License to your work, attach the following
182
- boilerplate notice, with the fields enclosed by brackets "[]"
183
- replaced with your own identifying information. (Don't include
184
- the brackets!) The text should be enclosed in the appropriate
185
- comment syntax for the file format. We also recommend that a
186
- file or class name and description of purpose be included on the
187
- same "printed page" as the copyright notice for easier
188
- identification within third-party archives.
189
-
190
- Copyright 2021 PlanetScale, Inc.
191
-
192
- Licensed under the Apache License, Version 2.0 (the "License");
193
- you may not use this file except in compliance with the License.
194
- You may obtain a copy of the License at
195
-
196
- http://www.apache.org/licenses/LICENSE-2.0
197
-
198
- Unless required by applicable law or agreed to in writing, software
199
- distributed under the License is distributed on an "AS IS" BASIS,
200
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
- See the License for the specific language governing permissions and
202
- limitations under the License.
@@ -1,476 +0,0 @@
1
- package proxy
2
-
3
- import (
4
- "context"
5
- "crypto/tls"
6
- "crypto/x509"
7
- "errors"
8
- "fmt"
9
- "io"
10
- "net"
11
- "os"
12
- "strings"
13
- "sync/atomic"
14
- "time"
15
-
16
- "go.uber.org/zap"
17
- )
18
-
19
- const (
20
- keepAlivePeriod = time.Minute
21
- )
22
-
23
- // CertError represents a Cert operation error.
24
- type CertError struct{ msg string }
25
-
26
- func (c *CertError) Error() string { return c.msg }
27
-
28
- // Cert represents the client certificate key pair in the root certiciate
29
- // authority that the client uses to verify server certificates.
30
-
31
- type Cert struct {
32
- ClientCert tls.Certificate
33
- CACerts []*x509.Certificate
34
- RemoteAddr string
35
- Ports RemotePorts
36
- }
37
-
38
- type RemotePorts struct {
39
- Proxy int
40
- MySQL int
41
- }
42
-
43
- // CertSource is used
44
- type CertSource interface {
45
- // Cert returns the required certs needed to establish a TLS connection
46
- // from the client to the server.
47
- Cert(ctx context.Context, org, db, branch string) (*Cert, error)
48
- }
49
-
50
- // Client is responsible for listening to unsecured connections over a TCP
51
- // localhost port and tunneling them securely over a TLS connection to a remote
52
- // database instance defined by its PlanetScale unique branch identifier.
53
- type Client struct {
54
- // connectionsCounter is used to enforce the optional maxConnections limit
55
- // NOTE: don't move this field, as we need to make sure the fields are
56
- // 64-bit aligned
57
- connectionsCounter uint64
58
-
59
- remoteAddr string
60
- localAddr string
61
- instance string
62
- maxConnections uint64
63
- certSource CertSource
64
-
65
- log *zap.Logger
66
-
67
- // configCache contains the TLS certificate chache for each indiviual
68
- // database
69
- configCache *tlsCache
70
-
71
- listener net.Listener
72
- // done is closed after a successfull net.Listen bind.
73
- done chan struct{}
74
- }
75
-
76
- // Options are the options for creating a new Client.
77
- type Options struct {
78
- // RemoteAddr defines the server address to tunnel local connections. By
79
- // default we connect to the remote address given by the CertSource. This
80
- // option can be used to over write it.
81
- RemoteAddr string
82
-
83
- // LocalAddr defines the address to listen for new connection
84
- LocalAddr string
85
-
86
- // Instance defines the remote DB instance to proxy new connection
87
- Instance string
88
-
89
- // MaxConnections is the maximum number of connections to establish
90
- // before refusing new connections. 0 means no limit.
91
- MaxConnections uint64
92
-
93
- // CertSource defines the certificate source to obtain the required TLS
94
- // certificates for the client and the remote address of the server to
95
- // connect.
96
- CertSource CertSource
97
-
98
- // Logger defines which zap.Logger to use. Use it to override the default
99
- // Development logger . Useful for tests.
100
- Logger *zap.Logger
101
- }
102
-
103
- // NewClient creates a new proxy client instance
104
- func NewClient(opts Options) (*Client, error) {
105
- c := &Client{
106
- certSource: opts.CertSource,
107
- localAddr: opts.LocalAddr,
108
- remoteAddr: opts.RemoteAddr,
109
- instance: opts.Instance,
110
- configCache: newtlsCache(),
111
- done: make(chan struct{}),
112
- }
113
-
114
- if opts.Logger != nil {
115
- c.log = opts.Logger
116
- } else {
117
- logger, err := zap.NewDevelopment(
118
- zap.Fields(zap.String("app", "sql-proxy-client")),
119
- )
120
- if err != nil {
121
- return nil, err
122
- }
123
- zap.ReplaceGlobals(logger)
124
- c.log = logger
125
- }
126
-
127
- return c, nil
128
- }
129
-
130
- // Conn represents a connection from a client to a specific instance.
131
- type Conn struct {
132
- Instance string
133
- Conn net.Conn
134
- }
135
-
136
- // Run runs the proxy. It listens to the configured localhost address and
137
- // proxies the connection over a TLS tunnel to the remote DB instance.
138
- func (c *Client) Run(ctx context.Context) error {
139
- // cache the certs for the given instance. This will also validate the
140
- // input and ensure to exit early.
141
- _, _, err := c.clientCerts(context.Background(), c.instance)
142
- if err != nil {
143
- return &CertError{msg: err.Error()}
144
- }
145
-
146
- c.log.Info("ready for new connections")
147
- l, err := c.getListener()
148
- if err != nil {
149
- return fmt.Errorf("error net.Listen: %w", err)
150
- }
151
- defer c.log.Sync() // nolint: errcheck
152
-
153
- c.listener = l
154
- close(c.done)
155
-
156
- return c.run(ctx, l)
157
- }
158
-
159
- // LocalAddr returns the address of the local listener. This is by default
160
- // blocking and will only return if the proxy is invoked with the Run() method.
161
- func (c *Client) LocalAddr() (net.Addr, error) {
162
- <-c.done
163
-
164
- if c.listener == nil {
165
- return nil, errors.New("listener is not set")
166
-
167
- }
168
- return c.listener.Addr(), nil
169
- }
170
-
171
- func (c *Client) getListener() (net.Listener, error) {
172
- if strings.HasPrefix(c.localAddr, "unix://") {
173
- p := strings.TrimPrefix(c.localAddr, "unix://")
174
- if err := os.Remove(p); err != nil && !os.IsNotExist(err) {
175
- return nil, fmt.Errorf("failed to remove unix domain socket file %s, error: %s", p, err)
176
- }
177
- return net.Listen("unix", p)
178
- }
179
- return net.Listen("tcp", c.localAddr)
180
- }
181
-
182
- // run is an internal function for testing the Client proxy event loop for
183
- // handling TCP connections
184
- func (c *Client) run(ctx context.Context, l net.Listener) error {
185
- connSrc := make(chan Conn, 1)
186
- go func() {
187
- if err := c.listen(l, connSrc); err != nil {
188
- c.log.Error("listen to local address", zap.Error(err))
189
- }
190
- }()
191
-
192
- for {
193
- select {
194
- case <-ctx.Done():
195
- termTimeout := time.Second * 1
196
- c.log.Info("received context cancellation, waiting until timeout",
197
- zap.Duration("timeout", termTimeout))
198
-
199
- err := c.Shutdown(termTimeout)
200
- if err != nil {
201
- return fmt.Errorf("error during shutdown: %v", err)
202
- }
203
- return nil
204
- case conn := <-connSrc:
205
- go func(lc Conn) {
206
- // TODO(fatih): detach context from parent
207
- err := c.handleConn(ctx, lc.Conn, lc.Instance)
208
- if err != nil {
209
- c.log.Error("error proxying conns", zap.Error(err))
210
- }
211
- }(conn)
212
- }
213
- }
214
- }
215
-
216
- // listen listens to the client's localAddres and sends each incoming
217
- // connections to the given connSrc channel.
218
- func (c *Client) listen(l net.Listener, connSrc chan<- Conn) error {
219
- c.log.Info("listening remote DB instance",
220
- zap.String("local_addr", c.localAddr),
221
- zap.String("instance", c.instance),
222
- )
223
-
224
- for {
225
- start := time.Now()
226
- conn, err := l.Accept()
227
- if err != nil {
228
- if nerr, ok := err.(net.Error); ok && nerr.Temporary() {
229
- d := 10*time.Millisecond - time.Since(start)
230
- if d > 0 {
231
- time.Sleep(d)
232
- }
233
- continue
234
- }
235
- l.Close()
236
-
237
- return fmt.Errorf("error in accept for on %v: %w", c.localAddr, err)
238
- }
239
-
240
- c.log.Info("new connection", zap.String("conn_addr", l.Addr().String()))
241
-
242
- switch clientConn := conn.(type) {
243
- case *net.TCPConn:
244
- clientConn.SetKeepAlive(true) //nolint: errcheck
245
- clientConn.SetKeepAlivePeriod(1 * time.Minute) //nolint: errcheck
246
- }
247
-
248
- connSrc <- Conn{
249
- Conn: conn,
250
- Instance: c.instance,
251
- }
252
- }
253
- }
254
-
255
- func (c *Client) handleConn(ctx context.Context, conn net.Conn, instance string) error {
256
- log := c.log.With(zap.String("instance", instance))
257
- active := atomic.AddUint64(&c.connectionsCounter, 1)
258
-
259
- // Deferred decrement of ConnectionsCounter upon connection closing
260
- defer atomic.AddUint64(&c.connectionsCounter, ^uint64(0))
261
-
262
- if c.maxConnections > 0 && active > c.maxConnections {
263
- conn.Close()
264
- return fmt.Errorf("too many open connections (max %d)", c.maxConnections)
265
- }
266
-
267
- cfg, remoteAddr, err := c.clientCerts(ctx, instance)
268
- if err != nil {
269
- return fmt.Errorf("couldn't retrieve certs for instance: %q: %w", instance, err)
270
- }
271
-
272
- // TODO(fatih): implement refreshing certs
273
- // go p.refreshCertAfter(instance, timeToRefresh)
274
-
275
- // overwrite the remote address if the user explicitly set it
276
- if c.remoteAddr != "" {
277
- remoteAddr = c.remoteAddr
278
- }
279
-
280
- c.log.Info("connecting to remote server", zap.String("remote_addr", remoteAddr))
281
-
282
- var d net.Dialer
283
- remoteConn, err := d.DialContext(ctx, "tcp", remoteAddr)
284
- if err != nil {
285
- conn.Close()
286
- return fmt.Errorf("couldn't connect to %q: %v", remoteAddr, err)
287
- }
288
-
289
- type setKeepAliver interface {
290
- SetKeepAlive(keepalive bool) error
291
- SetKeepAlivePeriod(d time.Duration) error
292
- }
293
-
294
- if s, ok := conn.(setKeepAliver); ok {
295
- if err := s.SetKeepAlive(true); err != nil {
296
- log.Error("couldn't set KeepAlive to true", zap.Error(err))
297
- } else if err := s.SetKeepAlivePeriod(keepAlivePeriod); err != nil {
298
- log.Error("couldn't set KeepAlivePeriod", zap.Error(err), zap.Duration("keep_alive_period", keepAlivePeriod))
299
- }
300
- } else {
301
- log.Warn("KeepAlive not supported: long-running tcp connections may be killed by the OS.")
302
- }
303
-
304
- secureConn := tls.Client(remoteConn, cfg)
305
- if err := secureConn.Handshake(); err != nil {
306
- secureConn.Close()
307
- return fmt.Errorf("couldn't initiate TLS handshake to remote addr: %s", err)
308
- }
309
-
310
- // Hasta la vista, baby
311
- copyThenClose(
312
- secureConn,
313
- conn,
314
- "remote connection",
315
- "local connection on "+conn.LocalAddr().String(),
316
- )
317
- return nil
318
- }
319
-
320
- // clientCerts returns the TLS configuration needed for the TLS handshake and
321
- // connection
322
- func (c *Client) clientCerts(ctx context.Context, instance string) (*tls.Config, string, error) {
323
- cacheEntry, err := c.configCache.Get(instance)
324
- if err == nil {
325
- c.log.Info("using tls.Config from the cache", zap.String("instance", instance))
326
- return cacheEntry.cfg, cacheEntry.remoteAddr, nil
327
- }
328
-
329
- if err != errConfigNotFound {
330
- return nil, "", err // we don't handle non errConfigNotFound errors
331
- }
332
-
333
- s := strings.Split(instance, "/")
334
- if len(s) != 3 {
335
- return nil, "", fmt.Errorf("instance format is malformed, should be in form organization/dbname/branch, have: %q", instance)
336
- }
337
-
338
- cert, err := c.certSource.Cert(ctx, s[0], s[1], s[2])
339
- if err != nil {
340
- return nil, "", fmt.Errorf("couldn't retrieve certs from cert source: %s", err)
341
- }
342
-
343
- rootCertPool := x509.NewCertPool()
344
- for _, caCert := range cert.CACerts {
345
- rootCertPool.AddCert(caCert)
346
- }
347
-
348
- serverName := fmt.Sprintf("%s.%s.%s.%s", s[2], s[1], s[0], cert.RemoteAddr)
349
- fullAddr := fmt.Sprintf("%s:%d", serverName, cert.Ports.Proxy)
350
-
351
- cfg := &tls.Config{
352
- ServerName: serverName,
353
- Certificates: []tls.Certificate{cert.ClientCert},
354
- MinVersion: tls.VersionTLS12,
355
- RootCAs: rootCertPool,
356
- // Set InsecureSkipVerify to skip the default validation we are
357
- // replacing. This will not disable VerifyConnection.
358
- InsecureSkipVerify: true,
359
- VerifyConnection: func(cs tls.ConnectionState) error {
360
- // For now, only verify the server's certificate chain.
361
- // We don't know yet what the server's FQDN will be.
362
- //
363
- // serverName := cs.ServerName
364
- // commonName := cs.PeerCertificates[0].Subject.CommonName
365
- // if commonName != serverName {
366
- // return fmt.Errorf("invalid certificate name %q, expected %q", commonName, serverName)
367
- // }
368
- opts := x509.VerifyOptions{
369
- Roots: rootCertPool,
370
- Intermediates: x509.NewCertPool(),
371
- }
372
- for _, cert := range cs.PeerCertificates[1:] {
373
- opts.Intermediates.AddCert(cert)
374
- }
375
- _, err := cs.PeerCertificates[0].Verify(opts)
376
- return err
377
- },
378
- }
379
-
380
- c.log.Info("adding tls.Config to the cache", zap.String("instance", instance))
381
- c.configCache.Add(instance, cfg, fullAddr)
382
- return cfg, fullAddr, nil
383
- }
384
-
385
- // Shutdown waits up to a given amount of time for all active connections to
386
- // close. Returns an error if there are still active connections after waiting
387
- // for the whole length of the timeout.
388
- func (c *Client) Shutdown(timeout time.Duration) error {
389
- term, ticker := time.After(timeout), time.NewTicker(100*time.Millisecond)
390
- defer ticker.Stop()
391
-
392
- for {
393
- select {
394
- case <-ticker.C:
395
- if atomic.LoadUint64(&c.connectionsCounter) > 0 {
396
- continue
397
- }
398
- c.log.Info("no connections to wait, bailing out")
399
- case <-term:
400
- }
401
- break
402
- }
403
-
404
- active := atomic.LoadUint64(&c.connectionsCounter)
405
- if active == 0 {
406
- return nil
407
- }
408
- return fmt.Errorf("%d active connections still exist after waiting for %v", active, timeout)
409
- }
410
-
411
- func copyThenClose(remote, local io.ReadWriteCloser, remoteDesc, localDesc string) {
412
- firstErr := make(chan error, 1)
413
-
414
- go func() {
415
- readErr, err := myCopy(remote, local)
416
- select {
417
- case firstErr <- err:
418
- if readErr && err == io.EOF {
419
- zap.L().Info("client closed connection",
420
- zap.String("local_desc", localDesc))
421
- } else {
422
- logError(localDesc, remoteDesc, readErr, err)
423
- }
424
- remote.Close()
425
- local.Close()
426
- default:
427
- }
428
- }()
429
-
430
- readErr, err := myCopy(local, remote)
431
- select {
432
- case firstErr <- err:
433
- if readErr && err == io.EOF {
434
- zap.L().Info("instance closed connection",
435
- zap.String("remote_desc", remoteDesc))
436
- } else {
437
- logError(remoteDesc, localDesc, readErr, err)
438
- }
439
- remote.Close()
440
- local.Close()
441
- default:
442
- // In this case, the other goroutine exited first and already printed its
443
- // error (and closed the things).
444
- }
445
- }
446
-
447
- func logError(readDesc, writeDesc string, readErr bool, err error) {
448
- var desc string
449
- if readErr {
450
- desc = "reading data from " + readDesc
451
- } else {
452
- desc = "writing data to " + writeDesc
453
- }
454
- zap.L().Error("copy error", zap.String("desc", desc), zap.Error(err))
455
- }
456
-
457
- // myCopy is similar to io.Copy, but reports whether the returned error was due
458
- // to a bad read or write. The returned error will never be nil
459
- func myCopy(dst io.Writer, src io.Reader) (readErr bool, err error) {
460
- buf := make([]byte, 4096)
461
- for {
462
- n, err := src.Read(buf)
463
- if n > 0 {
464
- if _, werr := dst.Write(buf[:n]); werr != nil {
465
- if err == nil {
466
- return false, werr
467
- }
468
- // Read and write error; just report read error (it happened first).
469
- return true, err
470
- }
471
- }
472
- if err != nil {
473
- return true, err
474
- }
475
- }
476
- }