Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Greatly improved forms with dbt profile browsing #8

Merged
merged 4 commits into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions fetch_dbt_profiles.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package main

import (
"log"
"os"
"path/filepath"

"gopkg.in/yaml.v2"
)

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"`
} `yaml:"outputs"`
}

type DbtProfiles map[string]DbtProfile

func FetchDbtProfiles() (DbtProfiles, error) {
paths := []string{
filepath.Join(".", "profiles.yml"),
filepath.Join(os.Getenv("HOME"), ".dbt", "profiles.yml"),
}
ps := DbtProfiles{}
for _, path := range paths {
pf := DbtProfiles{}
yf, err := os.ReadFile(path)
if err != nil {
continue
}
if err = yaml.Unmarshal(yf, pf); err != nil {
log.Fatalf("Could not read dbt profile, \nlikely unsupported fields or formatting issues\n please open an issue: %v\n", err)
}
for k, v := range pf {
ps[k] = v
}
}
return ps, nil
}
28 changes: 28 additions & 0 deletions fetch_dbt_profiles_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package main

import (
"os"
"testing"
)

func TestFetchDbtProfiles(t *testing.T) {
CreateTempDbtProfiles(t)
defer os.RemoveAll(os.Getenv("HOME"))
defer os.Unsetenv("HOME")
profiles, err := FetchDbtProfiles()
if err != nil {
t.Fatalf("Error fetching dbt profiles: %v\n", err)
}
if err != nil {
t.Fatalf("Error fetching dbt profiles: %v\n", err)
}
if profiles["elf"].Outputs["dev"].ConnType != "snowflake" {
t.Fatalf("Expected snowflake, got %s\n", profiles["elf"].Outputs["dev"].ConnType)
}
if profiles["human"].Outputs["dev"].ConnType != "bigquery" {
t.Fatalf("Expected bigquery, got %s\n", profiles["human"].Outputs["dev"].ConnType)
}
if profiles["dwarf"].Outputs["dev"].ConnType != "duckdb" {
t.Fatalf("Expected duckdb, got %s\n", profiles["dwarf"].Outputs["dev"].ConnType)
}
}
Loading