Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
2 changes: 1 addition & 1 deletion coderd/database/dump.sql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE ONLY licenses ALTER COLUMN uuid DROP NOT NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- We need to assign uuids to any existing licenses that don't have them.
UPDATE licenses SET uuid = gen_random_uuid() WHERE uuid IS NULL;
-- Assert no licenses have null uuids.
ALTER TABLE ONLY licenses ALTER COLUMN uuid SET NOT NULL;
4 changes: 2 additions & 2 deletions coderd/database/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions coderd/database/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions coderd/database/sqlc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ overrides:
troubleshooting_url: TroubleshootingURL
default_ttl: DefaultTTL
motd_file: MOTDFile
uuid: UUID

sql:
- schema: "./dump.sql"
Expand Down
2 changes: 1 addition & 1 deletion coderd/telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ func ConvertTemplateVersion(version database.TemplateVersion) TemplateVersion {
func ConvertLicense(license database.License) License {
return License{
UploadedAt: license.UploadedAt,
UUID: license.Uuid.UUID,
UUID: license.UUID,
}
}

Expand Down
5 changes: 1 addition & 4 deletions coderd/telemetry/telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,7 @@ func TestTelemetry(t *testing.T) {
UploadedAt: database.Now(),
JWT: "",
Exp: database.Now().Add(time.Hour),
Uuid: uuid.NullUUID{
UUID: uuid.New(),
Valid: true,
},
UUID: uuid.New(),
})
assert.NoError(t, err)
_, snapshot := collectSnapshot(t, db)
Expand Down
2 changes: 2 additions & 0 deletions enterprise/coderd/coderdenttest/coderdenttest.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"

"github.com/golang-jwt/jwt/v4"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -128,6 +129,7 @@ func GenerateLicense(t *testing.T, options LicenseOptions) string {

c := &license.Claims{
RegisteredClaims: jwt.RegisteredClaims{
ID: uuid.NewString(),
Issuer: "test@testing.test",
ExpiresAt: jwt.NewNumericDate(options.ExpiresAt),
NotBefore: jwt.NewNumericDate(time.Now().Add(-time.Minute)),
Expand Down
15 changes: 10 additions & 5 deletions enterprise/coderd/licenses.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,19 @@ func (api *API) postLicense(rw http.ResponseWriter, r *http.Request) {
}

id, err := uuid.Parse(claims.ID)
if err != nil {
// If no uuid is in the license, we generate a random uuid.
// This is not ideal, and this should be fixed to require a uuid
// for all licenses. We require this patch to support older licenses.
// TODO: In the future (April 2023?) we should remove this and reissue
// old licenses with a uuid.
id = uuid.New()
}
dl, err := api.Database.InsertLicense(ctx, database.InsertLicenseParams{
UploadedAt: database.Now(),
JWT: addLicense.License,
Exp: expTime,
Uuid: uuid.NullUUID{
UUID: id,
Valid: err == nil,
},
UUID: id,
})
if err != nil {
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
Expand Down Expand Up @@ -229,7 +234,7 @@ func (api *API) deleteLicense(rw http.ResponseWriter, r *http.Request) {
func convertLicense(dl database.License, c jwt.MapClaims) codersdk.License {
return codersdk.License{
ID: dl.ID,
UUID: dl.Uuid.UUID,
UUID: dl.UUID,
UploadedAt: dl.UploadedAt,
Claims: c,
}
Expand Down
8 changes: 4 additions & 4 deletions enterprise/trialer/trialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ func New(db database.Store, url string, keys map[string]ed25519.PublicKey) func(
return xerrors.Errorf("parse claims: %w", err)
}
id, err := uuid.Parse(claims.ID)
if err != nil {
return xerrors.Errorf("parse uuid: %w", err)
}
_, err = db.InsertLicense(ctx, database.InsertLicenseParams{
UploadedAt: database.Now(),
JWT: string(raw),
Exp: expTime,
Uuid: uuid.NullUUID{
UUID: id,
Valid: err == nil,
},
UUID: id,
})
if err != nil {
return xerrors.Errorf("insert license: %w", err)
Expand Down