Skip to content
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
45 changes: 45 additions & 0 deletions drivers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"net/url"
"os"
"path"
"path/filepath"
"runtime"
"runtime/debug"
"slices"
Expand All @@ -21,6 +22,8 @@ import (
"github.com/Masterminds/semver/v3"
"github.com/ProtonMail/gopenpgp/v3/crypto"
"github.com/goccy/go-yaml"
"github.com/google/uuid"
machineid "github.com/zeroshade/machine-id"
)

const defaultURL = "https://dbc-cdn.columnar.tech"
Expand All @@ -29,6 +32,8 @@ var (
baseURL = defaultURL
Version = "unknown"
userAgent string
mid string
uid uuid.UUID
)

func init() {
Expand All @@ -50,6 +55,41 @@ func init() {
userAgent += " CI"
}
}

mid, _ = machineid.ProtectedID()

// get user config dir
userdir, err := os.UserConfigDir()
if err != nil {
// if we can't get the dir for some reason, just generate a new UUID
uid = uuid.New()
return
}

// try to read the existing UUID file
dirname := "columnar"
if runtime.GOOS == "windows" || runtime.GOOS == "darwin" {
dirname = "Columnar"
}

fp := filepath.Join(userdir, dirname, "dbc", "uid.uuid")
data, err := os.ReadFile(fp)
if err == nil {
if err = uid.UnmarshalBinary(data); err == nil {
return
}
}

// if the file didn't exist or we couldn't parse it, generate a new uuid
// and then write a new file
uid = uuid.New()
// if we fail to create the dir or write the file, just ignore the error
// and use the fresh UUID
if err = os.MkdirAll(filepath.Dir(fp), 0o700); err == nil {
if data, err = uid.MarshalBinary(); err == nil {
os.WriteFile(fp, data, 0o600)
}
}
}

func makereq(u string) (resp *http.Response, err error) {
Expand All @@ -58,6 +98,11 @@ func makereq(u string) (resp *http.Response, err error) {
return nil, fmt.Errorf("failed to parse URL %s: %w", uri, err)
}

q := uri.Query()
q.Add("mid", mid)
q.Add("uid", uid.String())
uri.RawQuery = q.Encode()

req := http.Request{
Method: http.MethodGet,
URL: uri,
Expand Down
9 changes: 7 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module github.com/columnar-tech/dbc

go 1.24.2
go 1.24.4

toolchain go1.24.6

require (
github.com/Masterminds/semver/v3 v3.4.0
Expand All @@ -10,9 +12,11 @@ require (
github.com/charmbracelet/bubbletea v1.3.7
github.com/charmbracelet/lipgloss v1.1.0
github.com/goccy/go-yaml v1.17.1
github.com/google/uuid v1.6.0
github.com/pelletier/go-toml/v2 v2.2.4
github.com/stretchr/testify v1.10.0
golang.org/x/sys v0.34.0
github.com/zeroshade/machine-id v0.0.0-20250917170903-4283e98485ba
golang.org/x/sys v0.36.0
gopkg.in/yaml.v3 v3.0.1
)

Expand All @@ -27,6 +31,7 @@ require (
github.com/charmbracelet/x/cellbuf v0.0.13 // indirect
github.com/charmbracelet/x/term v0.2.1 // indirect
github.com/cloudflare/circl v1.6.1 // indirect
github.com/columnar-tech/machine-id v0.0.0-20250917165521-f900c2b8afc9 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/kr/text v0.2.0 // indirect
Expand Down
10 changes: 8 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQ
github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg=
github.com/cloudflare/circl v1.6.1 h1:zqIqSPIndyBh1bjLVVDHMPpVKqp8Su/V+6MeDzzQBQ0=
github.com/cloudflare/circl v1.6.1/go.mod h1:uddAzsPgqdMAYatqJ0lsjX1oECcQLIlRpzZh3pJrofs=
github.com/columnar-tech/machine-id v0.0.0-20250917165521-f900c2b8afc9 h1:RwPia8bI7oTl++lBMNT9EGCU2ICb4kN5uVJ9phl9Sak=
github.com/columnar-tech/machine-id v0.0.0-20250917165521-f900c2b8afc9/go.mod h1:REaxLA5IqWLxjhHfVtYguP/4z4eKMZtf3KeYmPf68N0=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
Expand All @@ -42,6 +44,8 @@ github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
github.com/goccy/go-yaml v1.17.1 h1:LI34wktB2xEE3ONG/2Ar54+/HJVBriAGJ55PHls4YuY=
github.com/goccy/go-yaml v1.17.1/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
Expand Down Expand Up @@ -76,14 +80,16 @@ github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOf
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
github.com/zeroshade/machine-id v0.0.0-20250917170903-4283e98485ba h1:yStvOL+OyJJ41jmZVqHqAspXXr4VVKC3gIfnGvO/+Pw=
github.com/zeroshade/machine-id v0.0.0-20250917170903-4283e98485ba/go.mod h1:RHX47A/DYmoTfyT25mb6C+Eve7X5miOporc+RVUoRoY=
golang.org/x/crypto v0.38.0 h1:jt+WWG8IZlBnVbomuhg2Mdq0+BBQaHbtqHEFEigjUV8=
golang.org/x/crypto v0.38.0/go.mod h1:MvrbAqul58NNYPKnOra203SB9vpuZW0e+RRZV+Ggqjw=
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561 h1:MDc5xs78ZrZr3HMQugiXOAkSZtfTpbJLDr/lwfgO53E=
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.34.0 h1:H5Y5sJ2L2JRdyv7ROF1he/lPdvFsd0mJHFw2ThKHxLA=
golang.org/x/sys v0.34.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k=
golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/text v0.25.0 h1:qVyWApTSYLk/drJRO5mDlNYskwQznZmkpV2c8q9zls4=
golang.org/x/text v0.25.0/go.mod h1:WEdwpYrmk1qmdHvhkSTNPm3app7v4rsT8F2UD6+VHIA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
Loading