- Notifications
You must be signed in to change notification settings - Fork923
feat(cli): include license status in support bundle#18472
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Draft
kacpersaw wants to merge1 commit intomainChoose a base branch fromkacpersaw/add-license-status-to-support-bundle
base:main
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
+140 −78
Draft
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
97 changes: 97 additions & 0 deletionscli/cliutil/license.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package cliutil | ||
import ( | ||
"fmt" | ||
"strings" | ||
"time" | ||
"github.com/google/uuid" | ||
"golang.org/x/xerrors" | ||
"github.com/coder/coder/v2/cli/cliui" | ||
"github.com/coder/coder/v2/codersdk" | ||
) | ||
// LicenseFormatterOpts are options for the license formatter. | ||
type LicenseFormatterOpts struct { | ||
Sanitize bool // If true, the UUID of the license will be redacted. | ||
} | ||
// NewLicenseFormatter returns a new license formatter. | ||
// The formatter will return a table and JSON output. | ||
func NewLicenseFormatter(opts LicenseFormatterOpts) *cliui.OutputFormatter { | ||
type tableLicense struct { | ||
ID int32 `table:"id,default_sort"` | ||
UUID uuid.UUID `table:"uuid" format:"uuid"` | ||
UploadedAt time.Time `table:"uploaded at" format:"date-time"` | ||
// Features is the formatted string for the license claims. | ||
// Used for the table view. | ||
Features string `table:"features"` | ||
ExpiresAt time.Time `table:"expires at" format:"date-time"` | ||
Trial bool `table:"trial"` | ||
} | ||
return cliui.NewOutputFormatter( | ||
cliui.ChangeFormatterData( | ||
cliui.TableFormat([]tableLicense{}, []string{"ID", "UUID", "Expires At", "Uploaded At", "Features"}), | ||
func(data any) (any, error) { | ||
list, ok := data.([]codersdk.License) | ||
if !ok { | ||
return nil, xerrors.Errorf("invalid data type %T", data) | ||
} | ||
out := make([]tableLicense, 0, len(list)) | ||
for _, lic := range list { | ||
var formattedFeatures string | ||
features, err := lic.FeaturesClaims() | ||
if err != nil { | ||
formattedFeatures = xerrors.Errorf("invalid license: %w", err).Error() | ||
} else { | ||
var strs []string | ||
if lic.AllFeaturesClaim() { | ||
// If all features are enabled, just include that | ||
strs = append(strs, "all features") | ||
} else { | ||
for k, v := range features { | ||
if v > 0 { | ||
// Only include claims > 0 | ||
strs = append(strs, fmt.Sprintf("%s=%v", k, v)) | ||
} | ||
} | ||
} | ||
formattedFeatures = strings.Join(strs, ", ") | ||
} | ||
// If this returns an error, a zero time is returned. | ||
exp, _ := lic.ExpiresAt() | ||
// If sanitize is true, we redact the UUID. | ||
if opts.Sanitize { | ||
lic.UUID = uuid.Nil | ||
} | ||
out = append(out, tableLicense{ | ||
ID: lic.ID, | ||
UUID: lic.UUID, | ||
UploadedAt: lic.UploadedAt, | ||
Features: formattedFeatures, | ||
ExpiresAt: exp, | ||
Trial: lic.Trial(), | ||
}) | ||
} | ||
return out, nil | ||
}), | ||
cliui.ChangeFormatterData(cliui.JSONFormat(), func(data any) (any, error) { | ||
list, ok := data.([]codersdk.License) | ||
if !ok { | ||
return nil, xerrors.Errorf("invalid data type %T", data) | ||
} | ||
for i := range list { | ||
humanExp, err := list[i].ExpiresAt() | ||
if err == nil { | ||
list[i].Claims[codersdk.LicenseExpiryClaim+"_human"] = humanExp.Format(time.RFC3339) | ||
} | ||
} | ||
return list, nil | ||
}), | ||
) | ||
} |
2 changes: 2 additions & 0 deletionscli/support.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletionscli/support_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
74 changes: 2 additions & 72 deletionsenterprise/cli/licenses.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
41 changes: 35 additions & 6 deletionssupport/support.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletionssupport/support_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.