mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: Add the option to generate a trial license during setup (#5110)
This allows users to generate a 30 day free license during setup to test out Enterprise features.
This commit is contained in:
@@ -446,6 +446,17 @@ func (r *remoteReporter) createSnapshot() (*Snapshot, error) {
|
||||
}
|
||||
return nil
|
||||
})
|
||||
eg.Go(func() error {
|
||||
licenses, err := r.options.Database.GetUnexpiredLicenses(ctx)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("get licenses: %w", err)
|
||||
}
|
||||
snapshot.Licenses = make([]License, 0, len(licenses))
|
||||
for _, license := range licenses {
|
||||
snapshot.Licenses = append(snapshot.Licenses, ConvertLicense(license))
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
err := eg.Wait()
|
||||
if err != nil {
|
||||
@@ -622,6 +633,14 @@ func ConvertTemplateVersion(version database.TemplateVersion) TemplateVersion {
|
||||
return snapVersion
|
||||
}
|
||||
|
||||
// ConvertLicense anonymizes a license.
|
||||
func ConvertLicense(license database.License) License {
|
||||
return License{
|
||||
UploadedAt: license.UploadedAt,
|
||||
UUID: license.Uuid.UUID,
|
||||
}
|
||||
}
|
||||
|
||||
// Snapshot represents a point-in-time anonymized database dump.
|
||||
// Data is aggregated by latest on the server-side, so partial data
|
||||
// can be sent without issue.
|
||||
@@ -631,6 +650,7 @@ type Snapshot struct {
|
||||
APIKeys []APIKey `json:"api_keys"`
|
||||
ParameterSchemas []ParameterSchema `json:"parameter_schemas"`
|
||||
ProvisionerJobs []ProvisionerJob `json:"provisioner_jobs"`
|
||||
Licenses []License `json:"licenses"`
|
||||
Templates []Template `json:"templates"`
|
||||
TemplateVersions []TemplateVersion `json:"template_versions"`
|
||||
Users []User `json:"users"`
|
||||
@@ -791,6 +811,11 @@ type ParameterSchema struct {
|
||||
ValidationCondition string `json:"validation_condition"`
|
||||
}
|
||||
|
||||
type License struct {
|
||||
UploadedAt time.Time `json:"uploaded_at"`
|
||||
UUID uuid.UUID `json:"uuid"`
|
||||
}
|
||||
|
||||
type noopReporter struct{}
|
||||
|
||||
func (*noopReporter) Report(_ *Snapshot) {}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/go-chi/chi"
|
||||
"github.com/google/uuid"
|
||||
@@ -87,9 +88,20 @@ func TestTelemetry(t *testing.T) {
|
||||
CreatedAt: database.Now(),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
_, err = db.InsertLicense(ctx, database.InsertLicenseParams{
|
||||
UploadedAt: database.Now(),
|
||||
JWT: "",
|
||||
Exp: database.Now().Add(time.Hour),
|
||||
Uuid: uuid.NullUUID{
|
||||
UUID: uuid.New(),
|
||||
Valid: true,
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
snapshot := collectSnapshot(t, db)
|
||||
require.Len(t, snapshot.ParameterSchemas, 1)
|
||||
require.Len(t, snapshot.ProvisionerJobs, 1)
|
||||
require.Len(t, snapshot.Licenses, 1)
|
||||
require.Len(t, snapshot.Templates, 1)
|
||||
require.Len(t, snapshot.TemplateVersions, 1)
|
||||
require.Len(t, snapshot.Users, 1)
|
||||
|
||||
Reference in New Issue
Block a user