Skip to content
Closed
1 change: 1 addition & 0 deletions coderd/database/dbauthz/dbauthz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2567,6 +2567,7 @@ func (s *MethodTestSuite) TestSystemFunctions() {
ID: uuid.New(),
Health: database.WorkspaceAppHealthDisabled,
SharingLevel: database.AppSharingLevelOwner,
CORSBehavior: database.AppCorsBehaviorSimple,
}).Asserts(rbac.ResourceSystem, policy.ActionCreate)
}))
s.Run("InsertWorkspaceResourceMetadata", s.Subtest(func(db database.Store, check *expects) {
Expand Down
1 change: 1 addition & 0 deletions coderd/database/dbgen/dbgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,7 @@ func WorkspaceApp(t testing.TB, db database.Store, orig database.WorkspaceApp) d
Health: takeFirst(orig.Health, database.WorkspaceAppHealthHealthy),
DisplayOrder: takeFirst(orig.DisplayOrder, 1),
Hidden: orig.Hidden,
CORSBehavior: takeFirst(orig.CORSBehavior, database.AppCorsBehaviorSimple),
})
require.NoError(t, err, "insert app")
return resource
Expand Down
5 changes: 5 additions & 0 deletions coderd/database/dbmem/dbmem.go
Original file line number Diff line number Diff line change
Expand Up @@ -8155,6 +8155,10 @@ func (q *FakeQuerier) InsertWorkspaceApp(_ context.Context, arg database.InsertW
arg.SharingLevel = database.AppSharingLevelOwner
}

if arg.CORSBehavior == "" {
arg.CORSBehavior = database.AppCorsBehaviorSimple
}

// nolint:gosimple
workspaceApp := database.WorkspaceApp{
ID: arg.ID,
Expand All @@ -8174,6 +8178,7 @@ func (q *FakeQuerier) InsertWorkspaceApp(_ context.Context, arg database.InsertW
Health: arg.Health,
Hidden: arg.Hidden,
DisplayOrder: arg.DisplayOrder,
CORSBehavior: arg.CORSBehavior,
}
q.workspaceApps = append(q.workspaceApps, workspaceApp)
return workspaceApp, nil
Expand Down
8 changes: 7 additions & 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,4 @@
ALTER TABLE workspace_apps
DROP COLUMN IF EXISTS cors_behavior;

DROP TYPE IF EXISTS app_cors_behavior;
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CREATE TYPE app_cors_behavior AS ENUM (
'simple',
'passthru'
);

-- https://www.postgresql.org/docs/16/sql-altertable.html
-- When a column is added with ADD COLUMN and a non-volatile DEFAULT is specified, the default is evaluated at the time
-- of the statement and the result stored in the table's metadata. That value will be used for the column for all existing rows.
ALTER TABLE workspace_apps
ADD COLUMN cors_behavior app_cors_behavior NOT NULL DEFAULT 'simple'::app_cors_behavior;
61 changes: 60 additions & 1 deletion coderd/database/models.go

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

18 changes: 13 additions & 5 deletions coderd/database/queries.sql.go

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

3 changes: 2 additions & 1 deletion coderd/database/queries/workspaceapps.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ INSERT INTO
external,
subdomain,
sharing_level,
cors_behavior,
healthcheck_url,
healthcheck_interval,
healthcheck_threshold,
Expand All @@ -32,7 +33,7 @@ INSERT INTO
hidden
)
VALUES
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17) RETURNING *;
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18) RETURNING *;

-- name: UpdateWorkspaceAppHealthByID :exec
UPDATE
Expand Down
2 changes: 2 additions & 0 deletions coderd/database/sqlc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ sql:
login_type_oauth2_provider_app: LoginTypeOAuth2ProviderApp
crypto_key_feature_workspace_apps_api_key: CryptoKeyFeatureWorkspaceAppsAPIKey
crypto_key_feature_oidc_convert: CryptoKeyFeatureOIDCConvert
app_cors_behavior: AppCORSBehavior
cors_behavior: CORSBehavior
rules:
- name: do-not-use-public-schema-in-queries
message: "do not use public schema in queries"
Expand Down
9 changes: 9 additions & 0 deletions coderd/provisionerdserver/provisionerdserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -1992,6 +1992,14 @@ func InsertWorkspaceResource(ctx context.Context, db database.Store, jobID uuid.
sharingLevel = database.AppSharingLevelPublic
}

var corsBehavior database.AppCORSBehavior
switch app.CorsBehavior {
case sdkproto.AppCORSBehavior_PASSTHRU:
corsBehavior = database.AppCorsBehaviorPassthru
default:
corsBehavior = database.AppCorsBehaviorSimple
}

dbApp, err := db.InsertWorkspaceApp(ctx, database.InsertWorkspaceAppParams{
ID: uuid.New(),
CreatedAt: dbtime.Now(),
Expand All @@ -2010,6 +2018,7 @@ func InsertWorkspaceResource(ctx context.Context, db database.Store, jobID uuid.
External: app.External,
Subdomain: app.Subdomain,
SharingLevel: sharingLevel,
CORSBehavior: corsBehavior,
HealthcheckUrl: app.Healthcheck.Url,
HealthcheckInterval: app.Healthcheck.Interval,
HealthcheckThreshold: app.Healthcheck.Threshold,
Expand Down
Loading
Loading