Skip to content

Commit 71ecfac

Browse files
committed
only download license for trial_started accounts
1 parent 65773fe commit 71ecfac

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

auth/credentials.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"slices"
2828
"sync"
2929

30+
"github.com/golang-jwt/jwt/v5"
3031
"github.com/pelletier/go-toml/v2"
3132
)
3233

@@ -267,7 +268,7 @@ func UpdateCreds() error {
267268
})
268269
}
269270

270-
var licenseURI = "https://dbc-cf-api.columnar.workers.dev/trial_license"
271+
const licenseURI = "https://dbc-cf-api.columnar.workers.dev/trial_license"
271272

272273
func FetchColumnarLicense(cred *Credential) error {
273274
licensePath := filepath.Join(filepath.Dir(credPath), "columnar.lic")
@@ -280,19 +281,29 @@ func FetchColumnarLicense(cred *Credential) error {
280281
return err
281282
}
282283

283-
req, err := http.NewRequest(http.MethodGet, licenseURI, nil)
284-
if err != nil {
285-
return err
286-
}
287-
288284
var authToken string
289285
switch cred.Type {
290286
case TypeApiKey:
291287
authToken = cred.ApiKey
292288
case TypeToken:
289+
p := jwt.NewParser()
290+
tk, err := p.Parse(cred.GetAuthToken(), nil)
291+
if err != nil && !errors.Is(err, jwt.ErrTokenUnverifiable) {
292+
return fmt.Errorf("failed to parse oauth token: %w", err)
293+
}
294+
295+
_, ok := tk.Claims.(jwt.MapClaims)["urn:columnar:trial_start"]
296+
if !ok {
297+
return nil // not a trial account
298+
}
293299
authToken = "Bearer " + cred.GetAuthToken()
294300
}
295301

302+
req, err := http.NewRequest(http.MethodGet, licenseURI, nil)
303+
if err != nil {
304+
return err
305+
}
306+
296307
req.Header.Add("authorization", authToken)
297308
resp, err := http.DefaultClient.Do(req)
298309
if err != nil {

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ require (
5252
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
5353
github.com/go-faster/errors v0.7.1 // indirect
5454
github.com/go-faster/jx v1.1.0 // indirect
55+
github.com/golang-jwt/jwt/v5 v5.3.0 // indirect
5556
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
5657
github.com/mattn/go-localereader v0.0.1 // indirect
5758
github.com/mattn/go-runewidth v0.0.16 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ github.com/go-faster/jx v1.1.0 h1:ZsW3wD+snOdmTDy9eIVgQdjUpXRRV4rqW8NS3t+20bg=
5151
github.com/go-faster/jx v1.1.0/go.mod h1:vKDNikrKoyUmpzaJ0OkIkRQClNHFX/nF3dnTJZb3skg=
5252
github.com/go-faster/yaml v0.4.6 h1:lOK/EhI04gCpPgPhgt0bChS6bvw7G3WwI8xxVe0sw9I=
5353
github.com/go-faster/yaml v0.4.6/go.mod h1:390dRIvV4zbnO7qC9FGo6YYutc+wyyUSHBgbXL52eXk=
54+
github.com/golang-jwt/jwt/v5 v5.3.0 h1:pv4AsKCKKZuqlgs5sUmn4x8UlGa0kEVt/puTpKx9vvo=
55+
github.com/golang-jwt/jwt/v5 v5.3.0/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE=
5456
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
5557
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
5658
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=

0 commit comments

Comments
 (0)