Skip to content

Commit

Permalink
support similar connect options as other clients
Browse files Browse the repository at this point in the history
This change adopts a connect API similar to the java script client
accepting a dsn string and an options object.

fixes #22
  • Loading branch information
fmoor committed Dec 17, 2020
1 parent aa18e44 commit 18f65b9
Show file tree
Hide file tree
Showing 21 changed files with 1,273 additions and 253 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- name: Install EdgeDB
env:
OS_NAME: ${{ matrix.os }}
SLOT: 1-alpha4
SLOT: 1-alpha7-dev5249
run: |
curl https://packages.edgedb.com/keys/edgedb.asc \
| sudo apt-key add -
Expand All @@ -55,6 +55,6 @@ jobs:
- name: Test
env:
EDGEDB_SLOT: 1-alpha4
EDGEDB_SLOT: 1-alpha7-dev5249
run: |
go test -race ./...
12 changes: 6 additions & 6 deletions connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ import (
"github.com/xdg/scram"
)

func (c *baseConn) connect(ctx context.Context, opts *Options) error {
func (c *baseConn) connect(ctx context.Context, cfg *connConfig) error {
buf := buff.New(nil)
buf.BeginMessage(message.ClientHandshake)
buf.PushUint16(0) // major version
buf.PushUint16(8) // minor version
buf.PushUint16(2) // number of parameters
buf.PushString("database")
buf.PushString(opts.Database)
buf.PushString(cfg.database)
buf.PushString("user")
buf.PushString(opts.User)
buf.PushString(cfg.user)
buf.PushUint16(0) // no extensions
buf.EndMessage()

Expand Down Expand Up @@ -78,7 +78,7 @@ func (c *baseConn) connect(ctx context.Context, opts *Options) error {
buf.PopBytes()
}

if err := c.authenticate(ctx, opts); err != nil {
if err := c.authenticate(ctx, cfg); err != nil {
return err
}
case message.ErrorResponse:
Expand All @@ -90,8 +90,8 @@ func (c *baseConn) connect(ctx context.Context, opts *Options) error {
return nil
}

func (c *baseConn) authenticate(ctx context.Context, opts *Options) error {
client, err := scram.SHA256.NewClient(opts.User, opts.Password, "")
func (c *baseConn) authenticate(ctx context.Context, cfg *connConfig) error {
client, err := scram.SHA256.NewClient(cfg.user, cfg.password, "")
if err != nil {
return err
}
Expand Down
11 changes: 2 additions & 9 deletions connect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,10 @@ import (
)

func TestAuth(t *testing.T) {
var host string
if opts.admin {
host = "localhost"
} else {
host = opts.Host
}

ctx := context.Background()
conn, err := ConnectOne(ctx, Options{
Host: host,
Port: opts.Port,
Hosts: opts.Hosts,
Ports: opts.Ports,
User: "user_with_password",
Password: "secret",
Database: opts.Database,
Expand Down
Loading

0 comments on commit 18f65b9

Please sign in to comment.