Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit733f58c

Browse files
authored
chore: Force license uuids to not be null (#6012)
* chore: Force license uuids to not be null* All unit tests generate uuids for licenses* Update migration files to new numbers* Put migration in transaction
1 parenta54de60 commit733f58c

File tree

11 files changed

+39
-25
lines changed

11 files changed

+39
-25
lines changed

‎coderd/database/dump.sql

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTERTABLE ONLY licenses ALTER COLUMN uuid DROPNOT NULL;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
BEGIN;
2+
3+
-- We need to assign uuids to any existing licenses that don't have them.
4+
UPDATE licensesSET uuid= gen_random_uuid()WHERE uuid ISNULL;
5+
-- Assert no licenses have null uuids.
6+
ALTERTABLE ONLY licenses ALTER COLUMN uuidSETNOT NULL;
7+
8+
COMMIT;

‎coderd/database/models.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/queries.sql.go

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/sqlc.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ overrides:
4343
troubleshooting_url:TroubleshootingURL
4444
default_ttl:DefaultTTL
4545
motd_file:MOTDFile
46+
uuid:UUID
4647

4748
sql:
4849
-schema:"./dump.sql"

‎coderd/telemetry/telemetry.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ func ConvertTemplateVersion(version database.TemplateVersion) TemplateVersion {
645645
funcConvertLicense(license database.License)License {
646646
returnLicense{
647647
UploadedAt:license.UploadedAt,
648-
UUID:license.Uuid.UUID,
648+
UUID:license.UUID,
649649
}
650650
}
651651

‎coderd/telemetry/telemetry_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,7 @@ func TestTelemetry(t *testing.T) {
7171
UploadedAt:database.Now(),
7272
JWT:"",
7373
Exp:database.Now().Add(time.Hour),
74-
Uuid: uuid.NullUUID{
75-
UUID:uuid.New(),
76-
Valid:true,
77-
},
74+
UUID:uuid.New(),
7875
})
7976
assert.NoError(t,err)
8077
_,snapshot:=collectSnapshot(t,db)

‎enterprise/coderd/coderdenttest/coderdenttest.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"time"
1212

1313
"github.com/golang-jwt/jwt/v4"
14+
"github.com/google/uuid"
1415
"github.com/stretchr/testify/assert"
1516
"github.com/stretchr/testify/require"
1617

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

129130
c:=&license.Claims{
130131
RegisteredClaims: jwt.RegisteredClaims{
132+
ID:uuid.NewString(),
131133
Issuer:"test@testing.test",
132134
ExpiresAt:jwt.NewNumericDate(options.ExpiresAt),
133135
NotBefore:jwt.NewNumericDate(time.Now().Add(-time.Minute)),

‎enterprise/coderd/licenses.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,19 @@ func (api *API) postLicense(rw http.ResponseWriter, r *http.Request) {
9898
}
9999

100100
id,err:=uuid.Parse(claims.ID)
101+
iferr!=nil {
102+
// If no uuid is in the license, we generate a random uuid.
103+
// This is not ideal, and this should be fixed to require a uuid
104+
// for all licenses. We require this patch to support older licenses.
105+
// TODO: In the future (April 2023?) we should remove this and reissue
106+
// old licenses with a uuid.
107+
id=uuid.New()
108+
}
101109
dl,err:=api.Database.InsertLicense(ctx, database.InsertLicenseParams{
102110
UploadedAt:database.Now(),
103111
JWT:addLicense.License,
104112
Exp:expTime,
105-
Uuid: uuid.NullUUID{
106-
UUID:id,
107-
Valid:err==nil,
108-
},
113+
UUID:id,
109114
})
110115
iferr!=nil {
111116
httpapi.Write(ctx,rw,http.StatusInternalServerError, codersdk.Response{
@@ -229,7 +234,7 @@ func (api *API) deleteLicense(rw http.ResponseWriter, r *http.Request) {
229234
funcconvertLicense(dl database.License,c jwt.MapClaims) codersdk.License {
230235
return codersdk.License{
231236
ID:dl.ID,
232-
UUID:dl.Uuid.UUID,
237+
UUID:dl.UUID,
233238
UploadedAt:dl.UploadedAt,
234239
Claims:c,
235240
}

‎enterprise/trialer/trialer.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ func New(db database.Store, url string, keys map[string]ed25519.PublicKey) func(
6464
returnxerrors.Errorf("parse claims: %w",err)
6565
}
6666
id,err:=uuid.Parse(claims.ID)
67+
iferr!=nil {
68+
returnxerrors.Errorf("parse uuid: %w",err)
69+
}
6770
_,err=db.InsertLicense(ctx, database.InsertLicenseParams{
6871
UploadedAt:database.Now(),
6972
JWT:string(raw),
7073
Exp:expTime,
71-
Uuid: uuid.NullUUID{
72-
UUID:id,
73-
Valid:err==nil,
74-
},
74+
UUID:id,
7575
})
7676
iferr!=nil {
7777
returnxerrors.Errorf("insert license: %w",err)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp