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:
Kyle Carberry
2022-11-16 17:09:49 -06:00
committed by GitHub
parent b6703b11c6
commit fb9ca7b830
29 changed files with 332 additions and 79 deletions
+25
View File
@@ -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) {}
+12
View File
@@ -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)