diff --git a/cmd/dbc/main.go b/cmd/dbc/main.go index d6b719eb..30774ce3 100644 --- a/cmd/dbc/main.go +++ b/cmd/dbc/main.go @@ -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) } @@ -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) + } } } diff --git a/drivers.go b/drivers.go index 22a6139a..a4a49a6e 100644 --- a/drivers.go +++ b/drivers.go @@ -16,6 +16,7 @@ package dbc import ( _ "embed" + "errors" "fmt" "io" "iter" @@ -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 @@ -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 }