Skip to content

Commit

Permalink
Adding config.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 committed Sep 30, 2024
1 parent 45ca0e9 commit a2608b9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/config/destination_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ type BigQuery struct {
Location string `yaml:"location"`
}

type Databricks struct {
Host string `yaml:"host"`
HttpPath string `json:"httpPath"`
Port int `yaml:"port"`
Catalog string `yaml:"catalog"`
PersonalAccessToken string `yaml:"personalAccessToken"`
}

type MSSQL struct {
Host string `yaml:"host"`
Port int `yaml:"port"`
Expand Down
15 changes: 15 additions & 0 deletions lib/config/destinations.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package config

import (
"cmp"
"fmt"
"net/url"
"strings"

"github.com/artie-labs/transfer/lib/cryptography"
"github.com/artie-labs/transfer/lib/typing"
Expand Down Expand Up @@ -72,3 +74,16 @@ func (s Snowflake) ToConfig() (*gosnowflake.Config, error) {

return cfg, nil
}

func (d Databricks) DSN() string {
query := url.Values{}
query.Add("catalog", d.Catalog)
u := &url.URL{
Path: d.HttpPath,
User: url.UserPassword("token", d.PersonalAccessToken),
Host: fmt.Sprintf("%s:%d", d.Host, cmp.Or(d.Port, 443)),
RawQuery: query.Encode(),
}

return strings.TrimPrefix(u.String(), "//")
}
19 changes: 19 additions & 0 deletions lib/config/destinations_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package config

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestDatabricks_DSN(t *testing.T) {
d := Databricks{
Host: "foo",
HttpPath: "/api/def",
Port: 443,
Catalog: "catalogName",
PersonalAccessToken: "pat",
}

assert.Equal(t, "token:pat@foo:443/api/def?catalog=catalogName", d.DSN())
}

0 comments on commit a2608b9

Please sign in to comment.