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
12 changes: 10 additions & 2 deletions cmd/dbc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,14 @@ func (m baseModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
cmd = tea.Println(errStyle.Render("Could not download license, trial has expired"))
case errors.Is(msg, auth.ErrNoTrialLicense):
cmd = tea.Println(errStyle.Render("Could not download license, trial not started"))
case errors.Is(msg, dbc.ErrUnauthorized):
cmd = tea.Sequence(tea.Println(errStyle.Render(msg.Error())),
tea.Println(msgStyle.Render("Did you run `dbc auth login`?")))
case errors.Is(msg, dbc.ErrUnauthorizedColumnar):
cmd = tea.Sequence(tea.Println(errStyle.Render(msg.Error())),
tea.Println(msgStyle.Render("Do you have an active license for this driver? Contact support@columnar.tech for assistance.")))
default:
cmd = tea.Println("Error: ", msg.Error())
cmd = tea.Println(errStyle.Render("Error: " + msg.Error()))
}
return m, tea.Sequence(cmd, tea.Quit)
}
Expand Down Expand Up @@ -227,7 +233,9 @@ func main() {

if !args.Quiet {
if fo, ok := m.(HasFinalOutput); ok {
fmt.Println(fo.FinalOutput())
if output := fo.FinalOutput(); output != "" {
fmt.Println(output)
}
}
}

Expand Down
17 changes: 17 additions & 0 deletions drivers.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package dbc

import (
_ "embed"
"errors"
"fmt"
"io"
"iter"
Expand All @@ -40,6 +41,11 @@ import (
machineid "github.com/zeroshade/machine-id"
)

var (
ErrUnauthorized = errors.New("not authorized")
ErrUnauthorizedColumnar = errors.New("not authorized to access")
)

type Registry struct {
Name string
Drivers []Driver
Expand Down Expand Up @@ -184,6 +190,17 @@ func makereq(u string) (resp *http.Response, err error) {
req.Header.Set("Authorization", "Bearer "+cred.GetAuthToken())
resp, err = DefaultClient.Do(&req)
}

switch resp.StatusCode {
case http.StatusUnauthorized, http.StatusForbidden:
err = ErrUnauthorized
if auth.IsColumnarPrivateRegistry(uri) && cred != nil {
err = ErrUnauthorizedColumnar
}
resp.Body.Close()
return nil, fmt.Errorf("%s%s: %w", uri.Host, uri.Path, err)
}

return resp, err
}

Expand Down
Loading