From a2608b926e7b8808266e1a8a522b4c54efffc4ab Mon Sep 17 00:00:00 2001 From: Robin Tang Date: Mon, 30 Sep 2024 11:50:22 -0700 Subject: [PATCH] Adding config. --- lib/config/destination_types.go | 8 ++++++++ lib/config/destinations.go | 15 +++++++++++++++ lib/config/destinations_test.go | 19 +++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 lib/config/destinations_test.go diff --git a/lib/config/destination_types.go b/lib/config/destination_types.go index 47cd94304..70068dacb 100644 --- a/lib/config/destination_types.go +++ b/lib/config/destination_types.go @@ -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"` diff --git a/lib/config/destinations.go b/lib/config/destinations.go index af04a0038..fe65580c1 100644 --- a/lib/config/destinations.go +++ b/lib/config/destinations.go @@ -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" @@ -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(), "//") +} diff --git a/lib/config/destinations_test.go b/lib/config/destinations_test.go new file mode 100644 index 000000000..2e98a67b4 --- /dev/null +++ b/lib/config/destinations_test.go @@ -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()) +}