Skip to content

feat(licenses): show license_expires time as rfc3339 date #7687

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions enterprise/cli/licenses.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"regexp"
"strconv"
"strings"
"time"

"golang.org/x/xerrors"

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

for _, license := range licenses {
convertLicenseExpireTime(license)
}

enc := json.NewEncoder(inv.Stdout)
enc.SetIndent("", " ")
return enc.Encode(licenses)
Expand Down Expand Up @@ -187,3 +192,20 @@ func (r *RootCmd) licenseDelete() *clibase.Cmd {
}
return cmd
}

func convertLicenseExpireTime(license codersdk.License) codersdk.License {
if license.Claims["license_expires"] != nil {
value, ok := license.Claims["license_expires"].(json.Number)
if !ok {
return license
}
int64Value, err := value.Int64()
if err != nil {
return license
}
t := time.Unix(int64Value, 0)
rfc3339Format := t.Format(time.RFC3339)
license.Claims["license_expires"] = rfc3339Format
}
return license
}
8 changes: 6 additions & 2 deletions enterprise/cli/licenses_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ func TestLicensesListFake(t *testing.T) {
assert.Equal(t, "claim1", licenses[0].Claims["h1"])
assert.Equal(t, int32(5), licenses[1].ID)
assert.Equal(t, "claim2", licenses[1].Claims["h2"])
assert.Equal(t, "2024-04-06T16:53:35Z", licenses[0].Claims["license_expires"])
assert.Equal(t, "anyvalue", licenses[1].Claims["license_expires"]) // keep value if not a time
})
}

Expand Down Expand Up @@ -294,7 +296,8 @@ func (s *fakeLicenseAPI) licenses(rw http.ResponseWriter, _ *http.Request) {
ID: 1,
UploadedAt: time.Now(),
Claims: map[string]interface{}{
"h1": "claim1",
"license_expires": 1712422415,
"h1": "claim1",
"features": map[string]int64{
"f1": 1,
"f2": 2,
Expand All @@ -305,7 +308,8 @@ func (s *fakeLicenseAPI) licenses(rw http.ResponseWriter, _ *http.Request) {
ID: 5,
UploadedAt: time.Now(),
Claims: map[string]interface{}{
"h2": "claim2",
"license_expires": "anyvalue",
"h2": "claim2",
"features": map[string]int64{
"f3": 3,
"f4": 4,
Expand Down