Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow username/password in connection string #27

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## 0.1.x (Unreleased)

## 0.1.5 (2022-10-12)

- Feat: Allow username/password in the DSN

## 0.1.4 (2022-07-30)

- Fix: Could not fetch rowsets greater than the value of `maxRows` (#18)
Expand Down
4 changes: 2 additions & 2 deletions databricks.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ type Options struct {
MaxRows int64
Timeout int
UserAgentEntry string

LogOut io.Writer
User string
LogOut io.Writer
}

const (
Expand Down
8 changes: 7 additions & 1 deletion driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ func parseURI(uri string) (*Options, error) {
if ok {
opts.Token = token
}
opts.User = u.User.Username()

} else {
return nil, fmt.Errorf("Token is required.")
}
Expand Down Expand Up @@ -157,7 +159,11 @@ func connect(opts *Options) (*Conn, error) {
}

httpOptions := thrift.THttpClientOptions{Client: httpClient}
endpointUrl := fmt.Sprintf("https://%s:%s@%s:%s"+opts.HTTPPath, "token", url.QueryEscape(opts.Token), opts.Host, opts.Port)
user := opts.User
if user == "" {
user = "token"
}
endpointUrl := fmt.Sprintf("https://%s:%s@%s:%s"+opts.HTTPPath, user, url.QueryEscape(opts.Token), opts.Host, opts.Port)
transport, err = thrift.NewTHttpClientTransportFactoryWithOptions(endpointUrl, httpOptions).GetTransport(socket)
if err != nil {
return nil, err
Expand Down