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 -}