Skip to content

Commit

Permalink
fix(dbt profiles): Expand type with all available options
Browse files Browse the repository at this point in the history
This commit attempts to add every available option on the DbtProfile type for the supported adapters, so that we don't throw an error when unmarshalling the YAML.
  • Loading branch information
gwenwindflower committed Apr 20, 2024
1 parent 7cf1bf4 commit 5065c92
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 13 deletions.
74 changes: 63 additions & 11 deletions fetch_dbt_profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,69 @@ import (
type DbtProfile struct {
Target string `yaml:"target"`
Outputs map[string]struct {
ConnType string `yaml:"type"`
Account string `yaml:"account"`
User string `yaml:"user"`
Role string `yaml:"role"`
Authenticator string `yaml:"authenticator"`
Database string `yaml:"database"`
Schema string `yaml:"schema"`
Project string `yaml:"project"`
Dataset string `yaml:"dataset"`
Path string `yaml:"path"`
Threads int `yaml:"threads"`
ConnType string `yaml:"type"`
Account string `yaml:"account"`
User string `yaml:"user"`
Role string `yaml:"role"`
Authenticator string `yaml:"authenticator"`
Database string `yaml:"database"`
Schema string `yaml:"schema"`
Project string `yaml:"project"`
Dataset string `yaml:"dataset"`
Path string `yaml:"path"`
Threads int `yaml:"threads"`
Password string `yaml:"password"`
Port int `yaml:"port"`
Warehouse string `yaml:"warehouse"`
Method string `yaml:"method"`
Host string `yaml:"host"`
PrivateKey string `yaml:"private_key"`
PrivateKeyPath string `yaml:"private_key_path"`
PrivateKeyPassphrase string `yaml:"private_key_passphrase"`
ClientSessionKeepAlive bool `yaml:"client_session_keep_alive"`
QueryTag string `yaml:"query_tag"`
ConnectRetries int `yaml:"connect_retries"`
ConnectTimeout int `yaml:"connect_timeout"`
RetryOnDatabaseErrors bool `yaml:"retry_on_database_errors"`
RetryAll bool `yaml:"retry_all"`
ReuseConnections bool `yaml:"reuse_connections"`
Extensions []string `yaml:"extensions"`
RefreshToken string `yaml:"refresh_token"`
ClientID string `yaml:"client_id"`
ClientSecret string `yaml:"client_secret"`
TokenURI string `yaml:"token_uri"`
Token string `yaml:"token"`
Priority string `yaml:"priority"`
Keyfile string `yaml:"keyfile"`
JobExecutionTimeoutSeconds int `yaml:"job_execution_timeout_seconds"`
JobCreationTimeoutSeconds int `yaml:"job_creation_timeout_seconds"`
JobRetryDeadlineSeconds int `yaml:"job_retry_deadline_seconds"`
Location string `yaml:"location"`
MaximumBytesBilled int `yaml:"maximum_bytes_billed"`
Scopes []string `yaml:"scopes"`
ImpersonateServiceAccount string `yaml:"impersonate_service_account"`
ExecutionProject string `yaml:"execution_project"`
GcsBucket string `yaml:"gcs_bucket"`
DataprocRegion string `yaml:"dataproc_region"`
DataprocClusterName string `yaml:"dataproc_cluster_name"`
DataprocBatch map[string]interface{} `yaml:"dataproc_batch"`
KeyfileJson map[string]struct {
Type string `yaml:"type"`
ProjectId string `yaml:"project_id"`
PrivateKeyId string `yaml:"private_key_id"`
PrivateKey string `yaml:"private_key"`
ClientEmail string `yaml:"client_email"`
ClientId string `yaml:"client_id"`
AuthURI string `yaml:"auth_uri"`
TokenURI string `yaml:"token_uri"`
AuthProviderX509CertUrl string `yaml:"auth_provider_x509_cert_url"`
ClientX509CertUrl string `yaml:"client_x509_cert_url"`
} `yaml:"keyfile_json"`
Settings map[string]struct {
S3Region string `yaml:"s3_region"`
S3AccessKeyID string `yaml:"s3_access_key_id"`
S3SecretAccessKey string `yaml:"s3_secret_access_key"`
} `yaml:"settings"`
} `yaml:"outputs"`
}

Expand Down
7 changes: 6 additions & 1 deletion set_connection_details.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,12 @@ func SetConnectionDetails(fr FormResponse, ps DbtProfiles) shared.ConnectionDeta
{
cd = shared.ConnectionDetails{
ConnType: fr.Warehouse,
Path: filepath.Join(wd, fr.Path),
Path: func() string {
if fr.Path == "md:" {
return "md:"
}
return filepath.Join(wd, fr.Path)
}(),
Database: fr.Database,
Schema: fr.Schema,
}
Expand Down
7 changes: 7 additions & 0 deletions sourcerer/connect_to_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ func (bqc *BqConn) ConnectToDb(ctx context.Context) (err error) {
func (dc *DuckConn) ConnectToDb(ctx context.Context) (err error) {
_, dc.Cancel = context.WithTimeout(ctx, 1*time.Minute)
defer dc.Cancel()
if dc.Path == "md:" {
dc.Db, err = sql.Open("duckdb", "md:")
if err != nil {
log.Fatalf("Could not connect to DuckDB %v\n", err)
}
return err
}
if _, err := os.Stat(dc.Path); os.IsNotExist(err) {
log.Fatalf("Path does not exist: %v\n", err)
}
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package main

const Version = "0.0.19"
const Version = "0.0.20"

0 comments on commit 5065c92

Please sign in to comment.