Skip to content

Commit ac2083b

Browse files
committed
feat(licenses): show license_expires time as rfc3339 date
1 parent 5eb41e8 commit ac2083b

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

enterprise/cli/licenses.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"regexp"
99
"strconv"
1010
"strings"
11+
"time"
1112

1213
"golang.org/x/xerrors"
1314

@@ -154,6 +155,10 @@ func (r *RootCmd) licensesList() *clibase.Cmd {
154155
licenses = make([]codersdk.License, 0)
155156
}
156157

158+
for _, license := range licenses {
159+
convertLicenseExpireTime(license)
160+
}
161+
157162
enc := json.NewEncoder(inv.Stdout)
158163
enc.SetIndent("", " ")
159164
return enc.Encode(licenses)
@@ -187,3 +192,20 @@ func (r *RootCmd) licenseDelete() *clibase.Cmd {
187192
}
188193
return cmd
189194
}
195+
196+
func convertLicenseExpireTime(license codersdk.License) codersdk.License {
197+
if license.Claims["license_expires"] != nil {
198+
value, ok := license.Claims["license_expires"].(json.Number)
199+
if !ok {
200+
return license
201+
}
202+
int64Value, err := value.Int64()
203+
if err != nil {
204+
return license
205+
}
206+
t := time.Unix(int64Value, 0)
207+
rfc3339Format := t.Format(time.RFC3339)
208+
license.Claims["license_expires"] = rfc3339Format
209+
}
210+
return license
211+
}

enterprise/cli/licenses_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ func TestLicensesListFake(t *testing.T) {
158158
assert.Equal(t, "claim1", licenses[0].Claims["h1"])
159159
assert.Equal(t, int32(5), licenses[1].ID)
160160
assert.Equal(t, "claim2", licenses[1].Claims["h2"])
161+
assert.Equal(t, "2024-04-06T16:53:35Z", licenses[0].Claims["license_expires"])
162+
assert.Equal(t, "anyvalue", licenses[1].Claims["license_expires"]) // keep value if not a time
161163
})
162164
}
163165

@@ -294,7 +296,8 @@ func (s *fakeLicenseAPI) licenses(rw http.ResponseWriter, _ *http.Request) {
294296
ID: 1,
295297
UploadedAt: time.Now(),
296298
Claims: map[string]interface{}{
297-
"h1": "claim1",
299+
"license_expires": 1712422415,
300+
"h1": "claim1",
298301
"features": map[string]int64{
299302
"f1": 1,
300303
"f2": 2,
@@ -305,7 +308,8 @@ func (s *fakeLicenseAPI) licenses(rw http.ResponseWriter, _ *http.Request) {
305308
ID: 5,
306309
UploadedAt: time.Now(),
307310
Claims: map[string]interface{}{
308-
"h2": "claim2",
311+
"license_expires": "anyvalue",
312+
"h2": "claim2",
309313
"features": map[string]int64{
310314
"f3": 3,
311315
"f4": 4,

0 commit comments

Comments
 (0)