planetscale 0.1.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.buildkite/pipeline.yml +21 -0
- data/.github/workflows/ci.yml +5 -6
- data/.github/workflows/gem-push.yml +4 -3
- data/.licenses/go/github.com/planetscale/planetscale-go/planetscale.dep.yml +56 -3
- data/.licenses/go/github.com/planetscale/sql-proxy/proxy.dep.yml +205 -172
- data/.licenses/go/go.uber.org/zap.dep.yml +1 -1
- data/.licenses/go/go.uber.org/zap/buffer.dep.yml +1 -1
- data/.licenses/go/go.uber.org/zap/internal/bufferpool.dep.yml +1 -1
- data/.licenses/go/go.uber.org/zap/internal/color.dep.yml +1 -1
- data/.licenses/go/go.uber.org/zap/internal/exit.dep.yml +1 -1
- data/.licenses/go/go.uber.org/zap/zapcore.dep.yml +1 -1
- data/README.md +9 -8
- data/controller.go +23 -10
- data/go.mod +3 -3
- data/go.sum +24 -23
- data/lib/generators/planetscale/install_generator.rb +8 -6
- data/lib/planetscale.rb +12 -12
- data/lib/planetscale/version.rb +1 -1
- data/planetscale.gemspec +1 -1
- data/proxy/planetscale-darwin.h +95 -0
- data/proxy/planetscale-darwin.so +0 -0
- data/proxy/planetscale-linux.h +95 -0
- data/proxy/planetscale-linux.so +0 -0
- data/vendor/github.com/planetscale/planetscale-go/LICENSE +202 -0
- data/vendor/github.com/planetscale/planetscale-go/planetscale/audit_logs.go +136 -0
- data/vendor/github.com/planetscale/planetscale-go/planetscale/branches.go +6 -12
- data/vendor/github.com/planetscale/planetscale-go/planetscale/certs.go +40 -16
- data/vendor/github.com/planetscale/planetscale-go/planetscale/client.go +13 -6
- data/vendor/github.com/planetscale/planetscale-go/planetscale/databases.go +2 -0
- data/vendor/github.com/planetscale/planetscale-go/planetscale/organizations.go +25 -0
- data/vendor/github.com/planetscale/planetscale-go/planetscale/regions.go +52 -0
- data/vendor/github.com/planetscale/planetscale-go/planetscale/service_tokens.go +1 -1
- data/vendor/github.com/planetscale/sql-proxy/LICENSE +202 -0
- data/vendor/github.com/planetscale/sql-proxy/proxy/client.go +17 -8
- data/vendor/go.uber.org/zap/CHANGELOG.md +60 -0
- data/vendor/go.uber.org/zap/CONTRIBUTING.md +0 -6
- data/vendor/go.uber.org/zap/FAQ.md +8 -0
- data/vendor/go.uber.org/zap/Makefile +13 -3
- data/vendor/go.uber.org/zap/README.md +4 -4
- data/vendor/go.uber.org/zap/buffer/buffer.go +18 -0
- data/vendor/go.uber.org/zap/field.go +10 -0
- data/vendor/go.uber.org/zap/go.mod +7 -6
- data/vendor/go.uber.org/zap/go.sum +25 -27
- data/vendor/go.uber.org/zap/http_handler.go +75 -24
- data/vendor/go.uber.org/zap/logger.go +11 -7
- data/vendor/go.uber.org/zap/options.go +8 -0
- data/vendor/go.uber.org/zap/sugar.go +21 -10
- data/vendor/go.uber.org/zap/zapcore/buffered_write_syncer.go +188 -0
- data/vendor/go.uber.org/zap/zapcore/clock.go +50 -0
- data/vendor/go.uber.org/zap/zapcore/console_encoder.go +1 -1
- data/vendor/go.uber.org/zap/zapcore/entry.go +2 -2
- data/vendor/go.uber.org/zap/zapcore/error.go +18 -1
- data/vendor/go.uber.org/zap/zapcore/field.go +7 -1
- data/vendor/go.uber.org/zap/zapcore/write_syncer.go +1 -2
- data/vendor/modules.txt +3 -3
- metadata +20 -10
- data/vendor/go.uber.org/zap/.travis.yml +0 -23
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# PlanetScale Ruby Client
|
2
|
+
[](https://rubygems.org/gems/planetscale)
|
2
3
|
|
3
4
|
This Gem provides an easy to use client for connecting your Ruby application to PlanetScale. It handles setting up a local proxy that allows you to connect to any PlanetScale database and branch without reconfiguration, so that you can easily swap and choose using only environment variables.
|
4
5
|
|
@@ -43,7 +44,7 @@ development:
|
|
43
44
|
database: <db_name>
|
44
45
|
```
|
45
46
|
|
46
|
-
Now, your Rails app will boot the proxy as the app is starting, and connect to the `main` branch on your DB.
|
47
|
+
Now, your Rails app will boot the proxy as the app is starting, and connect to the `main` branch on your DB.
|
47
48
|
|
48
49
|
### Service Token Authentication
|
49
50
|
|
@@ -66,11 +67,11 @@ To use this Gem in 'production', we'll start by creating a PlanetScale Service T
|
|
66
67
|
To configure your application in production, you'll need to feed it all of the right information via environment variables:
|
67
68
|
|
68
69
|
```
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
70
|
+
PLANETSCALE_ORG=<org_name>
|
71
|
+
PLANETSCALE_DB=<db_name>
|
72
|
+
PLANETSCALE_DB_BRANCH=main
|
73
|
+
PLANETSCALE_TOKEN_NAME=0sph6kvz5bxi
|
74
|
+
PLANETSCALE_TOKEN=<redacted>
|
74
75
|
```
|
75
76
|
|
76
77
|
## Development
|
@@ -81,8 +82,8 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
81
82
|
|
82
83
|
## Contributing
|
83
84
|
|
84
|
-
Bug reports and pull requests are welcome.
|
85
|
+
Bug reports and pull requests are welcome.
|
85
86
|
|
86
87
|
## License
|
87
88
|
|
88
|
-
|
89
|
+
This gem is licensed under the [Apache License Version 2.0](LICENSE).
|
data/controller.go
CHANGED
@@ -2,8 +2,9 @@ package main
|
|
2
2
|
|
3
3
|
import (
|
4
4
|
"context"
|
5
|
+
"crypto/ecdsa"
|
6
|
+
"crypto/elliptic"
|
5
7
|
"crypto/rand"
|
6
|
-
"crypto/rsa"
|
7
8
|
"crypto/tls"
|
8
9
|
"crypto/x509"
|
9
10
|
"encoding/pem"
|
@@ -174,7 +175,7 @@ func newRemoteCertSource(client *planetscale.Client) *remoteCertSource {
|
|
174
175
|
}
|
175
176
|
|
176
177
|
func (r *remoteCertSource) Cert(ctx context.Context, org, db, branch string) (*proxy.Cert, error) {
|
177
|
-
pkey, err :=
|
178
|
+
pkey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
|
178
179
|
if err != nil {
|
179
180
|
return nil, fmt.Errorf("couldn't generate private key: %s", err)
|
180
181
|
}
|
@@ -191,7 +192,7 @@ func (r *remoteCertSource) Cert(ctx context.Context, org, db, branch string) (*p
|
|
191
192
|
|
192
193
|
return &proxy.Cert{
|
193
194
|
ClientCert: cert.ClientCert,
|
194
|
-
|
195
|
+
CACerts: cert.CACerts,
|
195
196
|
RemoteAddr: cert.RemoteAddr,
|
196
197
|
Ports: proxy.RemotePorts{
|
197
198
|
Proxy: cert.Ports.Proxy,
|
@@ -213,7 +214,7 @@ func (l *localCertSource) Cert(ctx context.Context, org, db, branch string) (*pr
|
|
213
214
|
return nil, err
|
214
215
|
}
|
215
216
|
|
216
|
-
caCert, err :=
|
217
|
+
caCert, err := parseCerts(l.certChain)
|
217
218
|
if err != nil {
|
218
219
|
return nil, err
|
219
220
|
}
|
@@ -225,7 +226,7 @@ func (l *localCertSource) Cert(ctx context.Context, org, db, branch string) (*pr
|
|
225
226
|
|
226
227
|
return &proxy.Cert{
|
227
228
|
ClientCert: clientCert,
|
228
|
-
|
229
|
+
CACerts: caCert,
|
229
230
|
RemoteAddr: l.remoteAddr,
|
230
231
|
Ports: proxy.RemotePorts{
|
231
232
|
Proxy: port,
|
@@ -246,10 +247,22 @@ func logHandler(l *zap.Logger) func(http.Handler) http.Handler {
|
|
246
247
|
}
|
247
248
|
}
|
248
249
|
|
249
|
-
func
|
250
|
-
|
251
|
-
|
252
|
-
|
250
|
+
func parseCerts(pemCert string) ([]*x509.Certificate, error) {
|
251
|
+
perCertBlock := []byte(pemCert)
|
252
|
+
var certs []*x509.Certificate
|
253
|
+
|
254
|
+
for {
|
255
|
+
var certBlock *pem.Block
|
256
|
+
certBlock, perCertBlock = pem.Decode(perCertBlock)
|
257
|
+
if certBlock == nil {
|
258
|
+
break
|
259
|
+
}
|
260
|
+
cert, err := x509.ParseCertificate(certBlock.Bytes)
|
261
|
+
if err != nil {
|
262
|
+
return nil, err
|
263
|
+
}
|
264
|
+
|
265
|
+
certs = append(certs, cert)
|
253
266
|
}
|
254
|
-
return
|
267
|
+
return certs, nil
|
255
268
|
}
|
data/go.mod
CHANGED
@@ -7,9 +7,9 @@ require (
|
|
7
7
|
github.com/golang/protobuf v1.5.2 // indirect
|
8
8
|
github.com/gorilla/mux v1.8.0
|
9
9
|
github.com/mitchellh/go-homedir v1.1.0
|
10
|
-
github.com/planetscale/planetscale-go v0.
|
11
|
-
github.com/planetscale/sql-proxy v0.
|
12
|
-
go.uber.org/zap v1.
|
10
|
+
github.com/planetscale/planetscale-go v0.38.0
|
11
|
+
github.com/planetscale/sql-proxy v0.8.0
|
12
|
+
go.uber.org/zap v1.18.1
|
13
13
|
golang.org/x/net v0.0.0-20210410081132-afb366fc7cd1 // indirect
|
14
14
|
golang.org/x/oauth2 v0.0.0-20210413134643-5e61552d6c78 // indirect
|
15
15
|
google.golang.org/appengine v1.6.7 // indirect
|
data/go.sum
CHANGED
@@ -31,11 +31,12 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl
|
|
31
31
|
cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs=
|
32
32
|
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
|
33
33
|
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
|
34
|
-
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
|
35
34
|
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
36
35
|
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
37
36
|
github.com/armon/circbuf v0.0.0-20190214190532-5111143e8da2 h1:7Ip0wMmLHLRJdrloDxZfhMm0xrLXZS8+COSu2bXmEQs=
|
38
37
|
github.com/armon/circbuf v0.0.0-20190214190532-5111143e8da2/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
|
38
|
+
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
|
39
|
+
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
|
39
40
|
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
40
41
|
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
|
41
42
|
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
|
@@ -49,12 +50,12 @@ github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymF
|
|
49
50
|
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
50
51
|
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
|
51
52
|
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
52
|
-
github.com/frankban/quicktest v1.
|
53
|
-
github.com/frankban/quicktest v1.
|
54
|
-
github.com/frankban/quicktest v1.12.1/go.mod h1:qLE0fzW0VuyUAJgPU19zByoIr0HtCHN/r/VLSOOIySU=
|
53
|
+
github.com/frankban/quicktest v1.13.0 h1:yNZif1OkDfNoDfb9zZa9aXIpejNR4F23Wely0c+Qdqk=
|
54
|
+
github.com/frankban/quicktest v1.13.0/go.mod h1:qLE0fzW0VuyUAJgPU19zByoIr0HtCHN/r/VLSOOIySU=
|
55
55
|
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
|
56
56
|
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
|
57
57
|
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
|
58
|
+
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
|
58
59
|
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
59
60
|
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
60
61
|
github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
@@ -92,9 +93,9 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
|
|
92
93
|
github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
93
94
|
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
94
95
|
github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
95
|
-
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
96
|
-
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
|
97
96
|
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
97
|
+
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
|
98
|
+
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
98
99
|
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
|
99
100
|
github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
|
100
101
|
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
|
@@ -128,11 +129,13 @@ github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrk
|
|
128
129
|
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
129
130
|
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
130
131
|
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
131
|
-
github.com/planetscale/planetscale-go v0.
|
132
|
-
github.com/planetscale/planetscale-go v0.
|
133
|
-
github.com/planetscale/planetscale-go v0.
|
134
|
-
github.com/planetscale/
|
135
|
-
github.com/planetscale/
|
132
|
+
github.com/planetscale/planetscale-go v0.33.0/go.mod h1:99n+tnrvJaaUako3UZNCiC1dTtSPKr81GqAUNibw5pc=
|
133
|
+
github.com/planetscale/planetscale-go v0.36.0 h1:voNRDQ7FgbpuVJKlLZm6QgIByp0UnvyRtGmVZWQlSZY=
|
134
|
+
github.com/planetscale/planetscale-go v0.36.0/go.mod h1:99n+tnrvJaaUako3UZNCiC1dTtSPKr81GqAUNibw5pc=
|
135
|
+
github.com/planetscale/planetscale-go v0.38.0 h1:Sn6Xx1/u3xpU3v/mt1CdR38JXcTjej56rUpwuA3A5EY=
|
136
|
+
github.com/planetscale/planetscale-go v0.38.0/go.mod h1:99n+tnrvJaaUako3UZNCiC1dTtSPKr81GqAUNibw5pc=
|
137
|
+
github.com/planetscale/sql-proxy v0.8.0 h1:EeWQhocldn0ldrTxPIIIrbHWWqNqHrNFYiSdp4tUY0E=
|
138
|
+
github.com/planetscale/sql-proxy v0.8.0/go.mod h1:vOcL5jRMzaza+8q79hRRhMj3ABpYHy3cgenr2FOhDWU=
|
136
139
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
137
140
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
138
141
|
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
@@ -140,8 +143,8 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR
|
|
140
143
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
141
144
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
142
145
|
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
143
|
-
github.com/stretchr/testify v1.
|
144
|
-
github.com/stretchr/testify v1.
|
146
|
+
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
147
|
+
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
145
148
|
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
146
149
|
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
147
150
|
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
@@ -150,15 +153,14 @@ go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
|
|
150
153
|
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
|
151
154
|
go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
|
152
155
|
go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
|
153
|
-
go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
|
154
156
|
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
|
155
157
|
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
156
|
-
go.uber.org/
|
158
|
+
go.uber.org/goleak v1.1.10 h1:z+mqJhf6ss6BSfSM671tgKyZBFPTTJM+HLxnhPC3wu0=
|
159
|
+
go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A=
|
157
160
|
go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4=
|
158
161
|
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
|
159
|
-
go.uber.org/
|
160
|
-
go.uber.org/zap v1.
|
161
|
-
go.uber.org/zap v1.16.0/go.mod h1:MA8QOfq0BHJwdXa996Y4dYkAqRKB8/1K1QMMZVaNZjQ=
|
162
|
+
go.uber.org/zap v1.18.1 h1:CSUJ2mjFszzEWt4CdKISEuChVIXGBn3lAPwkRGyVrc4=
|
163
|
+
go.uber.org/zap v1.18.1/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI=
|
162
164
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
163
165
|
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
164
166
|
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
@@ -293,8 +295,7 @@ golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgw
|
|
293
295
|
golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
294
296
|
golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
295
297
|
golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
296
|
-
golang.org/x/tools v0.0.0-
|
297
|
-
golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
298
|
+
golang.org/x/tools v0.0.0-20191108193012-7d206e10da11/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
298
299
|
golang.org/x/tools v0.0.0-20191113191852-77e3bb0ad9e7/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
299
300
|
golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
300
301
|
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
@@ -410,18 +411,18 @@ gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogR
|
|
410
411
|
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
411
412
|
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
412
413
|
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
414
|
+
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
413
415
|
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
|
414
416
|
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
415
417
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
416
|
-
gopkg.in/yaml.v3 v3.0.0-
|
417
|
-
gopkg.in/yaml.v3 v3.0.0-
|
418
|
+
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
|
419
|
+
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
418
420
|
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
419
421
|
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
420
422
|
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
421
423
|
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
422
424
|
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
423
425
|
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
|
424
|
-
honnef.co/go/tools v0.0.1-2020.1.4 h1:UoveltGrhghAA7ePc+e+QYDHXrBps2PqFZiHkGR/xK8=
|
425
426
|
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
|
426
427
|
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
|
427
428
|
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
|
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'rails/generators'
|
2
2
|
|
3
3
|
class Planetscale
|
4
|
-
class InstallGenerator < Rails::Generators::Base
|
4
|
+
class InstallGenerator < Rails::Generators::Base
|
5
5
|
class_option :organization, type: :string, default: ''
|
6
6
|
|
7
7
|
def read_config
|
8
8
|
@database = "<db_name>"
|
9
|
-
file_path = File.join(Rails.root, PlanetScale::Proxy::
|
9
|
+
file_path = File.join(Rails.root, PlanetScale::Proxy::PLANETSCALE_FILE)
|
10
10
|
return unless File.exist?(file_path)
|
11
11
|
|
12
12
|
data = YAML.safe_load(File.read(file_path))
|
@@ -21,18 +21,20 @@ class Planetscale
|
|
21
21
|
end
|
22
22
|
|
23
23
|
@org ||= options[:organization]
|
24
|
-
end
|
24
|
+
end
|
25
|
+
|
26
|
+
APPLICATION_REQUIRE_REGEX = /(require_relative ("|')application("|')\n)/.freeze
|
25
27
|
|
26
28
|
def create_planetscale_config
|
27
29
|
create_file "config/planetscale.rb", "PlanetScale.start(org: '#{@org}')\n"
|
28
|
-
inject_into_file "config/environment.rb", after:
|
30
|
+
inject_into_file "config/environment.rb", after: APPLICATION_REQUIRE_REGEX do <<~'RUBY'
|
29
31
|
require_relative "planetscale"
|
30
32
|
RUBY
|
31
33
|
end
|
32
34
|
end
|
33
35
|
|
34
36
|
# todo(nickvanw): When we get rid of DB passwords, this can mostly go away, and we can just
|
35
|
-
# return the `DATABSE_URL` that the user should use.
|
37
|
+
# return the `DATABSE_URL` that the user should use.
|
36
38
|
def print_database_yaml
|
37
39
|
d =
|
38
40
|
<<~EOS
|
@@ -50,7 +52,7 @@ class Planetscale
|
|
50
52
|
puts d
|
51
53
|
puts "\nOr set DATABASE_URL=#{db_url}"
|
52
54
|
end
|
53
|
-
end
|
55
|
+
end
|
54
56
|
end
|
55
57
|
|
56
58
|
class String
|
data/lib/planetscale.rb
CHANGED
@@ -13,10 +13,10 @@ module PlanetScale
|
|
13
13
|
|
14
14
|
class Proxy
|
15
15
|
AUTH_SERVICE_TOKEN = 1 # Use Service Tokens for Auth
|
16
|
-
|
16
|
+
AUTH_PLANETSCALE = 2 # Use externally configured `pscale` auth & org config
|
17
17
|
AUTH_STATIC = 3 # Use a locally provided certificate
|
18
18
|
AUTH_AUTO = 4 # Default. Let the Gem figure it out
|
19
|
-
|
19
|
+
PLANETSCALE_FILE = '.pscale.yml'
|
20
20
|
|
21
21
|
class ProxyError < StandardError
|
22
22
|
end
|
@@ -36,26 +36,26 @@ module PlanetScale
|
|
36
36
|
@auth_method = auth_method
|
37
37
|
|
38
38
|
default_file = if defined?(Rails.root)
|
39
|
-
File.join(Rails.root,
|
39
|
+
File.join(Rails.root, PLANETSCALE_FILE) if defined?(Rails.root)
|
40
40
|
else
|
41
|
-
|
41
|
+
PLANETSCALE_FILE
|
42
42
|
end
|
43
43
|
|
44
|
-
@cfg_file = kwargs[:cfg_file] || ENV['
|
44
|
+
@cfg_file = kwargs[:cfg_file] || ENV['PLANETSCALE_DB_CONFIG'] || default_file
|
45
45
|
|
46
|
-
@branch_name = kwargs[:branch] || ENV['
|
46
|
+
@branch_name = kwargs[:branch] || ENV['PLANETSCALE_DB_BRANCH']
|
47
47
|
@branch = lookup_branch
|
48
48
|
|
49
|
-
@db_name = kwargs[:db] || ENV['
|
49
|
+
@db_name = kwargs[:db] || ENV['PLANETSCALE_DB']
|
50
50
|
@db = lookup_database
|
51
51
|
|
52
|
-
@org_name = kwargs[:org] || ENV['
|
52
|
+
@org_name = kwargs[:org] || ENV['PLANETSCALE_ORG']
|
53
53
|
@org = lookup_org
|
54
54
|
|
55
55
|
raise ArgumentError, 'missing required configuration variables' if [@db, @branch, @org].any?(&:nil?)
|
56
56
|
|
57
|
-
@token_name = kwargs[:token_id] || ENV['
|
58
|
-
@token = kwargs[:token] || ENV['
|
57
|
+
@token_name = kwargs[:token_id] || ENV['PLANETSCALE_TOKEN_NAME']
|
58
|
+
@token = kwargs[:token] || ENV['PLANETSCALE_TOKEN']
|
59
59
|
|
60
60
|
if @token && @token_name && auto_auth?
|
61
61
|
@auth_method = AUTH_SERVICE_TOKEN
|
@@ -78,7 +78,7 @@ module PlanetScale
|
|
78
78
|
|
79
79
|
def start
|
80
80
|
ret = case @auth_method
|
81
|
-
when
|
81
|
+
when AUTH_PLANETSCALE
|
82
82
|
startfromenv(@org, @db, @branch, @listen_addr)
|
83
83
|
when AUTH_AUTO
|
84
84
|
startfromenv(@org, @db, @branch, @listen_addr)
|
@@ -123,7 +123,7 @@ module PlanetScale
|
|
123
123
|
end
|
124
124
|
|
125
125
|
def env_auth?
|
126
|
-
@auth_method ==
|
126
|
+
@auth_method == AUTH_PLANETSCALE
|
127
127
|
end
|
128
128
|
|
129
129
|
def token_auth?
|
data/lib/planetscale/version.rb
CHANGED
data/planetscale.gemspec
CHANGED
@@ -35,7 +35,7 @@ Gem::Specification.new do |spec|
|
|
35
35
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
36
36
|
spec.require_paths = ['lib']
|
37
37
|
|
38
|
-
spec.add_development_dependency 'bundler', '~> 2
|
38
|
+
spec.add_development_dependency 'bundler', '~> 2'
|
39
39
|
spec.add_development_dependency 'rake', '>= 12.3.3'
|
40
40
|
spec.add_development_dependency 'pry'
|
41
41
|
spec.add_development_dependency 'minitest'
|
@@ -0,0 +1,95 @@
|
|
1
|
+
/* Code generated by cmd/cgo; DO NOT EDIT. */
|
2
|
+
|
3
|
+
/* package main */
|
4
|
+
|
5
|
+
|
6
|
+
#line 1 "cgo-builtin-export-prolog"
|
7
|
+
|
8
|
+
#include <stddef.h> /* for ptrdiff_t below */
|
9
|
+
|
10
|
+
#ifndef GO_CGO_EXPORT_PROLOGUE_H
|
11
|
+
#define GO_CGO_EXPORT_PROLOGUE_H
|
12
|
+
|
13
|
+
#ifndef GO_CGO_GOSTRING_TYPEDEF
|
14
|
+
typedef struct { const char *p; ptrdiff_t n; } _GoString_;
|
15
|
+
#endif
|
16
|
+
|
17
|
+
#endif
|
18
|
+
|
19
|
+
/* Start of preamble from import "C" comments. */
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
/* End of preamble from import "C" comments. */
|
25
|
+
|
26
|
+
|
27
|
+
/* Start of boilerplate cgo prologue. */
|
28
|
+
#line 1 "cgo-gcc-export-header-prolog"
|
29
|
+
|
30
|
+
#ifndef GO_CGO_PROLOGUE_H
|
31
|
+
#define GO_CGO_PROLOGUE_H
|
32
|
+
|
33
|
+
typedef signed char GoInt8;
|
34
|
+
typedef unsigned char GoUint8;
|
35
|
+
typedef short GoInt16;
|
36
|
+
typedef unsigned short GoUint16;
|
37
|
+
typedef int GoInt32;
|
38
|
+
typedef unsigned int GoUint32;
|
39
|
+
typedef long long GoInt64;
|
40
|
+
typedef unsigned long long GoUint64;
|
41
|
+
typedef GoInt64 GoInt;
|
42
|
+
typedef GoUint64 GoUint;
|
43
|
+
typedef __SIZE_TYPE__ GoUintptr;
|
44
|
+
typedef float GoFloat32;
|
45
|
+
typedef double GoFloat64;
|
46
|
+
typedef float _Complex GoComplex64;
|
47
|
+
typedef double _Complex GoComplex128;
|
48
|
+
|
49
|
+
/*
|
50
|
+
static assertion to make sure the file is being used on architecture
|
51
|
+
at least with matching size of GoInt.
|
52
|
+
*/
|
53
|
+
typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1];
|
54
|
+
|
55
|
+
#ifndef GO_CGO_GOSTRING_TYPEDEF
|
56
|
+
typedef _GoString_ GoString;
|
57
|
+
#endif
|
58
|
+
typedef void *GoMap;
|
59
|
+
typedef void *GoChan;
|
60
|
+
typedef struct { void *t; void *v; } GoInterface;
|
61
|
+
typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;
|
62
|
+
|
63
|
+
#endif
|
64
|
+
|
65
|
+
/* End of boilerplate cgo prologue. */
|
66
|
+
|
67
|
+
#ifdef __cplusplus
|
68
|
+
extern "C" {
|
69
|
+
#endif
|
70
|
+
|
71
|
+
|
72
|
+
/* Return type for startfromenv */
|
73
|
+
struct startfromenv_return {
|
74
|
+
char* r0;
|
75
|
+
char* r1;
|
76
|
+
};
|
77
|
+
extern struct startfromenv_return startfromenv(char* org, char* database, char* branch, char* listenAddr);
|
78
|
+
|
79
|
+
/* Return type for startfromtoken */
|
80
|
+
struct startfromtoken_return {
|
81
|
+
char* r0;
|
82
|
+
char* r1;
|
83
|
+
};
|
84
|
+
extern struct startfromtoken_return startfromtoken(char* tokenName, char* token, char* org, char* database, char* branch, char* listenAddr);
|
85
|
+
|
86
|
+
/* Return type for startfromstatic */
|
87
|
+
struct startfromstatic_return {
|
88
|
+
char* r0;
|
89
|
+
char* r1;
|
90
|
+
};
|
91
|
+
extern struct startfromstatic_return startfromstatic(char* org, char* database, char* branch, char* privKey, char* cert, char* chain, char* addr, char* port, char* listenAddr);
|
92
|
+
|
93
|
+
#ifdef __cplusplus
|
94
|
+
}
|
95
|
+
#endif
|