From bc89ef5f7fcb3e6d3c23afda011fc7d73143f5be Mon Sep 17 00:00:00 2001 From: Robin Tang Date: Wed, 25 Sep 2024 15:41:22 -0700 Subject: [PATCH] Move more. --- lib/config/bigquery.go | 15 ------- lib/config/config.go | 20 ++++++++++ lib/config/{snowflake.go => destination.go} | 29 +++++++++++++- lib/config/mssql.go | 43 --------------------- 4 files changed, 48 insertions(+), 59 deletions(-) delete mode 100644 lib/config/bigquery.go rename lib/config/{snowflake.go => destination.go} (60%) delete mode 100644 lib/config/mssql.go diff --git a/lib/config/bigquery.go b/lib/config/bigquery.go deleted file mode 100644 index d60f2cbed..000000000 --- a/lib/config/bigquery.go +++ /dev/null @@ -1,15 +0,0 @@ -package config - -import "fmt" - -// DSN - returns the notation for BigQuery following this format: bigquery://projectID/[location/]datasetID?queryString -// If location is passed in, we'll specify it. Else, it'll default to empty and our library will set it to US. -func (b *BigQuery) DSN() string { - dsn := fmt.Sprintf("bigquery://%s/%s", b.ProjectID, b.DefaultDataset) - - if b.Location != "" { - dsn = fmt.Sprintf("bigquery://%s/%s/%s", b.ProjectID, b.Location, b.DefaultDataset) - } - - return dsn -} diff --git a/lib/config/config.go b/lib/config/config.go index 7e588b92a..c21ef64f9 100644 --- a/lib/config/config.go +++ b/lib/config/config.go @@ -134,6 +134,26 @@ func (c Config) ValidateRedshift() error { return nil } +func (c Config) ValidateMSSQL() error { + if c.Output != constants.MSSQL { + return fmt.Errorf("output is not mssql, output: %v", c.Output) + } + + if c.MSSQL == nil { + return fmt.Errorf("mssql config is nil") + } + + if empty := stringutil.Empty(c.MSSQL.Host, c.MSSQL.Username, c.MSSQL.Password, c.MSSQL.Database); empty { + return fmt.Errorf("one of mssql settings is empty (host, username, password, database)") + } + + if c.MSSQL.Port <= 0 { + return fmt.Errorf("invalid mssql port: %d", c.MSSQL.Port) + } + + return nil +} + // Validate will check the output source validity // It will also check if a topic exists + iterate over each topic to make sure it's valid. // The actual output source (like Snowflake) and CDC parser will be loaded and checked by other funcs. diff --git a/lib/config/snowflake.go b/lib/config/destination.go similarity index 60% rename from lib/config/snowflake.go rename to lib/config/destination.go index 9b1c9aeb2..392dfce8b 100644 --- a/lib/config/snowflake.go +++ b/lib/config/destination.go @@ -2,12 +2,39 @@ package config import ( "fmt" + "net/url" "github.com/artie-labs/transfer/lib/cryptography" "github.com/artie-labs/transfer/lib/typing" - "github.com/snowflakedb/gosnowflake" + gosnowflake "github.com/snowflakedb/gosnowflake" ) +// DSN - returns the notation for BigQuery following this format: bigquery://projectID/[location/]datasetID?queryString +// If location is passed in, we'll specify it. Else, it'll default to empty and our library will set it to US. +func (b *BigQuery) DSN() string { + dsn := fmt.Sprintf("bigquery://%s/%s", b.ProjectID, b.DefaultDataset) + + if b.Location != "" { + dsn = fmt.Sprintf("bigquery://%s/%s/%s", b.ProjectID, b.Location, b.DefaultDataset) + } + + return dsn +} + +func (m MSSQL) DSN() string { + query := url.Values{} + query.Add("database", m.Database) + + u := &url.URL{ + Scheme: "sqlserver", + User: url.UserPassword(m.Username, m.Password), + Host: fmt.Sprintf("%s:%d", m.Host, m.Port), + RawQuery: query.Encode(), + } + + return u.String() +} + func (s Snowflake) ToConfig() (*gosnowflake.Config, error) { cfg := &gosnowflake.Config{ Account: s.AccountID, diff --git a/lib/config/mssql.go b/lib/config/mssql.go deleted file mode 100644 index c9179e33b..000000000 --- a/lib/config/mssql.go +++ /dev/null @@ -1,43 +0,0 @@ -package config - -import ( - "fmt" - "net/url" - - "github.com/artie-labs/transfer/lib/config/constants" - "github.com/artie-labs/transfer/lib/stringutil" -) - -func (m MSSQL) DSN() string { - query := url.Values{} - query.Add("database", m.Database) - - u := &url.URL{ - Scheme: "sqlserver", - User: url.UserPassword(m.Username, m.Password), - Host: fmt.Sprintf("%s:%d", m.Host, m.Port), - RawQuery: query.Encode(), - } - - return u.String() -} - -func (c Config) ValidateMSSQL() error { - if c.Output != constants.MSSQL { - return fmt.Errorf("output is not mssql, output: %v", c.Output) - } - - if c.MSSQL == nil { - return fmt.Errorf("mssql config is nil") - } - - if empty := stringutil.Empty(c.MSSQL.Host, c.MSSQL.Username, c.MSSQL.Password, c.MSSQL.Database); empty { - return fmt.Errorf("one of mssql settings is empty (host, username, password, database)") - } - - if c.MSSQL.Port <= 0 { - return fmt.Errorf("invalid mssql port: %d", c.MSSQL.Port) - } - - return nil -}