|
8 | 8 | "regexp"
|
9 | 9 | "strconv"
|
10 | 10 | "strings"
|
| 11 | + "time" |
11 | 12 |
|
12 | 13 | "golang.org/x/xerrors"
|
13 | 14 |
|
@@ -154,6 +155,14 @@ func (r *RootCmd) licensesList() *clibase.Cmd {
|
154 | 155 | licenses = make([]codersdk.License, 0)
|
155 | 156 | }
|
156 | 157 |
|
| 158 | + for i, license := range licenses { |
| 159 | + newClaims, err := convertLicenseExpireTime(license.Claims) |
| 160 | + if err != nil { |
| 161 | + return err |
| 162 | + } |
| 163 | + licenses[i].Claims = newClaims |
| 164 | + } |
| 165 | + |
157 | 166 | enc := json.NewEncoder(inv.Stdout)
|
158 | 167 | enc.SetIndent("", " ")
|
159 | 168 | return enc.Encode(licenses)
|
@@ -187,3 +196,29 @@ func (r *RootCmd) licenseDelete() *clibase.Cmd {
|
187 | 196 | }
|
188 | 197 | return cmd
|
189 | 198 | }
|
| 199 | + |
| 200 | +func convertLicenseExpireTime(licenseClaims map[string]interface{}) (map[string]interface{}, error) { |
| 201 | + if licenseClaims["license_expires"] != nil { |
| 202 | + licenseExpiresNumber, ok := licenseClaims["license_expires"].(json.Number) |
| 203 | + if !ok { |
| 204 | + return licenseClaims, xerrors.Errorf("could not convert license_expires to json.Number") |
| 205 | + } |
| 206 | + |
| 207 | + licenseExpires, err := licenseExpiresNumber.Int64() |
| 208 | + if err != nil { |
| 209 | + return licenseClaims, xerrors.Errorf("could not convert license_expires to int64: %w", err) |
| 210 | + } |
| 211 | + |
| 212 | + t := time.Unix(licenseExpires, 0) |
| 213 | + rfc3339Format := t.Format(time.RFC3339) |
| 214 | + |
| 215 | + claimsCopy := make(map[string]interface{}, len(licenseClaims)) |
| 216 | + for k, v := range licenseClaims { |
| 217 | + claimsCopy[k] = v |
| 218 | + } |
| 219 | + |
| 220 | + claimsCopy["license_expires"] = rfc3339Format |
| 221 | + return claimsCopy, nil |
| 222 | + } |
| 223 | + return licenseClaims, nil |
| 224 | +} |
0 commit comments