Skip to content

Commit 4913b8c

Browse files
author
Phani Raj
authored
Merge pull request #52 from planetscale/bail-on-non-edge-passwords
Ensure that hostname is an Edge host when checking connection status
2 parents 3be501c + 0d42fa9 commit 4913b8c

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

cmd/internal/planetscale_edge_database.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"io"
7+
"net/http"
78
"strings"
89
"time"
910

@@ -39,9 +40,25 @@ type PlanetScaleEdgeDatabase struct {
3940
}
4041

4142
func (p PlanetScaleEdgeDatabase) CanConnect(ctx context.Context, psc PlanetScaleSource) error {
43+
if err := p.checkEdgePassword(ctx, psc); err != nil {
44+
return errors.New("This password will not function with PlanetScale Connect. Please ensure that your organization is enrolled in the Connect beta. ")
45+
}
46+
4247
return p.Mysql.PingContext(ctx, psc)
4348
}
4449

50+
func (p PlanetScaleEdgeDatabase) checkEdgePassword(ctx context.Context, psc PlanetScaleSource) error {
51+
reqCtx, cancel := context.WithTimeout(ctx, 2*time.Second)
52+
defer cancel()
53+
req, err := http.NewRequestWithContext(reqCtx, http.MethodGet, fmt.Sprintf("https://%v", psc.Host), nil)
54+
if err != nil {
55+
return err
56+
}
57+
58+
_, err = http.DefaultClient.Do(req)
59+
return err
60+
}
61+
4562
func (p PlanetScaleEdgeDatabase) DiscoverSchema(ctx context.Context, psc PlanetScaleSource) (Catalog, error) {
4663
var c Catalog
4764

0 commit comments

Comments
 (0)