Skip to content

Commit c627606

Browse files
committed
add message if trial is not started
1 parent 71de23f commit c627606

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

auth/credentials.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,8 @@ func IsColumnarPrivateRegistry(u *url.URL) bool {
274274

275275
const licenseURI = "https://heimdall.columnar.tech/trial_license"
276276

277+
var ErrNoTrialLicense = errors.New("no trial license found")
278+
277279
func FetchColumnarLicense(cred *Credential) error {
278280
licensePath := filepath.Join(filepath.Dir(credPath), "columnar.lic")
279281
_, err := os.Stat(licensePath)
@@ -298,7 +300,7 @@ func FetchColumnarLicense(cred *Credential) error {
298300

299301
_, ok := tk.Claims.(jwt.MapClaims)["urn:columnar:trial_start"]
300302
if !ok {
301-
return nil // not a trial account
303+
return ErrNoTrialLicense
302304
}
303305
authToken = "Bearer " + cred.GetAuthToken()
304306
}

cmd/dbc/auth.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,11 @@ func (m loginModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
195195
return err
196196
}
197197

198-
if msg.RegistryURL.Host == auth.DefaultOauthURI {
198+
if auth.IsColumnarPrivateRegistry((*url.URL)(&msg.RegistryURL)) {
199199
return auth.FetchColumnarLicense(&msg)
200200
}
201201
return nil
202-
}, tea.Println("Authentication successful!"),
203-
tea.Quit)
202+
}, tea.Println("Authentication successful!"), tea.Quit)
204203
}
205204

206205
base, cmd := m.baseModel.Update(msg)

cmd/dbc/main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package main
1616

1717
import (
18+
"errors"
1819
"fmt"
1920
"os"
2021
"slices"
@@ -23,6 +24,7 @@ import (
2324
tea "github.com/charmbracelet/bubbletea"
2425
"github.com/charmbracelet/lipgloss"
2526
"github.com/columnar-tech/dbc"
27+
"github.com/columnar-tech/dbc/auth"
2628
"github.com/columnar-tech/dbc/cmd/dbc/completions"
2729
"github.com/columnar-tech/dbc/config"
2830
"github.com/mattn/go-isatty"
@@ -118,6 +120,9 @@ func (m baseModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
118120
return m, tea.Quit
119121
}
120122
case error:
123+
if errors.Is(msg, auth.ErrNoTrialLicense) {
124+
return m, tea.Println(errStyle.Render("Could not download license, trial not started"))
125+
}
121126
m.status = 1
122127
return m, tea.Sequence(tea.Println("Error: ", msg.Error()), tea.Quit)
123128
}

0 commit comments

Comments
 (0)