Skip to content

Commit 99fa810

Browse files
committed
Merge remote-tracking branch 'origin/main' into authzquerier_layer
2 parents d2c7a1f + 1c4e1d8 commit 99fa810

14 files changed

+49
-29
lines changed

coderd/database/dump.sql

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE ONLY licenses ALTER COLUMN uuid DROP NOT 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 licenses SET uuid = gen_random_uuid() WHERE uuid IS NULL;
5+
-- Assert no licenses have null uuids.
6+
ALTER TABLE ONLY licenses ALTER COLUMN uuid SET NOT NULL;
7+
8+
COMMIT;

coderd/database/models.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing 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 about customizing 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
func ConvertLicense(license database.License) License {
646646
return License{
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+
if err != 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
if err != 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
func convertLicense(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
return xerrors.Errorf("parse claims: %w", err)
6565
}
6666
id, err := uuid.Parse(claims.ID)
67+
if err != nil {
68+
return xerrors.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
if err != nil {
7777
return xerrors.Errorf("insert license: %w", err)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ require (
212212
github.com/fsnotify/fsnotify v1.6.0 // indirect
213213
github.com/fxamacker/cbor/v2 v2.4.0 // indirect
214214
github.com/ghodss/yaml v1.0.0 // indirect
215-
github.com/gin-gonic/gin v1.7.0 // indirect
215+
github.com/gin-gonic/gin v1.7.7 // indirect
216216
github.com/go-logr/stdr v1.2.2 // indirect
217217
github.com/go-ole/go-ole v1.2.6 // indirect
218218
github.com/go-openapi/jsonpointer v0.19.5 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -636,8 +636,8 @@ github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeME
636636
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
637637
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
638638
github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M=
639-
github.com/gin-gonic/gin v1.7.0 h1:jGB9xAJQ12AIGNB4HguylppmDK1Am9ppF7XnGXXJuoU=
640-
github.com/gin-gonic/gin v1.7.0/go.mod h1:jD2toBW3GZUr5UMcdrwQA10I7RuaFOl/SGeDjXkfUtY=
639+
github.com/gin-gonic/gin v1.7.7 h1:3DoBmSbJbZAWqXJC3SLjAPfutPJJRN1U5pALB7EeTTs=
640+
github.com/gin-gonic/gin v1.7.7/go.mod h1:axIBovoeJpVj8S3BwE0uPMTeReE4+AfFtqpqaZ1qq1U=
641641
github.com/github/fakeca v0.1.0 h1:Km/MVOFvclqxPM9dZBC4+QE564nU4gz4iZ0D9pMw28I=
642642
github.com/github/fakeca v0.1.0/go.mod h1:+bormgoGMMuamOscx7N91aOuUST7wdaJ2rNjeohylyo=
643643
github.com/go-chi/chi v1.5.4 h1:QHdzF2szwjqVV4wmByUnTcsbIg7UGaQ0tPF2t5GcAIs=

provisionerd/provisionerd_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1090,10 +1090,16 @@ func createProvisionerDaemonClient(t *testing.T, server provisionerDaemonTestSer
10901090
require.NoError(t, err)
10911091
srv := drpcserver.New(mux)
10921092
ctx, cancelFunc := context.WithCancel(context.Background())
1093-
t.Cleanup(cancelFunc)
1093+
closed := make(chan struct{})
10941094
go func() {
1095+
defer close(closed)
10951096
_ = srv.Serve(ctx, serverPipe)
10961097
}()
1098+
t.Cleanup(func() {
1099+
cancelFunc()
1100+
_ = serverPipe.Close()
1101+
<-closed
1102+
})
10971103
return proto.NewDRPCProvisionerDaemonClient(clientPipe)
10981104
}
10991105

0 commit comments

Comments
 (0)