Skip to content

Commit 15706b5

Browse files
authored
feat(install): give hint when unauthorized (#255)
closes #253
1 parent 1e9689d commit 15706b5

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

cmd/dbc/main.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,14 @@ func (m baseModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
127127
cmd = tea.Println(errStyle.Render("Could not download license, trial has expired"))
128128
case errors.Is(msg, auth.ErrNoTrialLicense):
129129
cmd = tea.Println(errStyle.Render("Could not download license, trial not started"))
130+
case errors.Is(msg, dbc.ErrUnauthorized):
131+
cmd = tea.Sequence(tea.Println(errStyle.Render(msg.Error())),
132+
tea.Println(msgStyle.Render("Did you run `dbc auth login`?")))
133+
case errors.Is(msg, dbc.ErrUnauthorizedColumnar):
134+
cmd = tea.Sequence(tea.Println(errStyle.Render(msg.Error())),
135+
tea.Println(msgStyle.Render("Do you have an active license for this driver? Contact support@columnar.tech for assistance.")))
130136
default:
131-
cmd = tea.Println("Error: ", msg.Error())
137+
cmd = tea.Println(errStyle.Render("Error: " + msg.Error()))
132138
}
133139
return m, tea.Sequence(cmd, tea.Quit)
134140
}
@@ -227,7 +233,9 @@ func main() {
227233

228234
if !args.Quiet {
229235
if fo, ok := m.(HasFinalOutput); ok {
230-
fmt.Println(fo.FinalOutput())
236+
if output := fo.FinalOutput(); output != "" {
237+
fmt.Println(output)
238+
}
231239
}
232240
}
233241

drivers.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package dbc
1616

1717
import (
1818
_ "embed"
19+
"errors"
1920
"fmt"
2021
"io"
2122
"iter"
@@ -40,6 +41,11 @@ import (
4041
machineid "github.com/zeroshade/machine-id"
4142
)
4243

44+
var (
45+
ErrUnauthorized = errors.New("not authorized")
46+
ErrUnauthorizedColumnar = errors.New("not authorized to access")
47+
)
48+
4349
type Registry struct {
4450
Name string
4551
Drivers []Driver
@@ -188,6 +194,17 @@ func makereq(u string) (resp *http.Response, err error) {
188194
req.Header.Set("Authorization", "Bearer "+cred.GetAuthToken())
189195
resp, err = DefaultClient.Do(&req)
190196
}
197+
198+
switch resp.StatusCode {
199+
case http.StatusUnauthorized, http.StatusForbidden:
200+
err = ErrUnauthorized
201+
if auth.IsColumnarPrivateRegistry(uri) && cred != nil {
202+
err = ErrUnauthorizedColumnar
203+
}
204+
resp.Body.Close()
205+
return nil, fmt.Errorf("%s%s: %w", uri.Host, uri.Path, err)
206+
}
207+
191208
return resp, err
192209
}
193210

0 commit comments

Comments
 (0)